~ubuntu-branches/ubuntu/raring/perl-tk/raring

« back to all changes in this revision

Viewing changes to pTk/mTk/unix/tkUnixWm.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Tuckley
  • Date: 2008-02-15 13:56:59 UTC
  • mfrom: (1.1.3 upstream) (4.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20080215135659-ru2oqlykuju20fav
Tags: 1:804.028-1
* New Upstream Release (Closes: #463080).
* Update to Debhelper v5.
* Build with XFT=1 (Closes: #411129).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * tkUnixWm.c --
3
3
 *
4
4
 *      This module takes care of the interactions between a Tk-based
5
 
 *      application and the window manager.  Among other things, it
6
 
 *      implements the "wm" command and passes geometry information
7
 
 *      to the window manager.
 
5
 *      application and the window manager. Among other things, it implements
 
6
 *      the "wm" command and passes geometry information to the window
 
7
 *      manager.
8
8
 *
9
9
 * Copyright (c) 1991-1994 The Regents of the University of California.
10
10
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
11
11
 *
12
 
 * See the file "license.terms" for information on usage and redistribution
13
 
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
12
 * See the file "license.terms" for information on usage and redistribution of
 
13
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
14
14
 *
15
 
 * RCS: @(#) $Id: tkUnixWm.c,v 1.36 2002/12/27 21:23:04 jenglish Exp $
 
15
 * RCS: @(#) $Id: tkUnixWm.c,v 1.51 2006/05/29 22:21:40 hobbs Exp $
16
16
 */
17
17
 
18
18
#include "tkPort.h"
19
19
#include "tkInt.h"
20
20
#include "tkUnixInt.h"
21
 
#include <errno.h>
22
21
 
23
22
/*
24
 
 * A data structure of the following type holds information for
25
 
 * each window manager protocol (such as WM_DELETE_WINDOW) for
26
 
 * which a handler (i.e. a Tcl command) has been defined for a
27
 
 * particular top-level window.
 
23
 * A data structure of the following type holds information for each window
 
24
 * manager protocol (such as WM_DELETE_WINDOW) for which a handler (i.e. a Tcl
 
25
 * command) has been defined for a particular top-level window.
28
26
 */
29
27
 
30
28
typedef struct ProtocolHandler {
31
29
    Atom protocol;              /* Identifies the protocol. */
32
30
    struct ProtocolHandler *nextPtr;
33
 
                                /* Next in list of protocol handlers for
34
 
                                 * the same top-level window, or NULL for
35
 
                                 * end of list. */
 
31
                                /* Next in list of protocol handlers for the
 
32
                                 * same top-level window, or NULL for end of
 
33
                                 * list. */
36
34
    Tcl_Interp *interp;         /* Interpreter in which to invoke command. */
37
35
#if 0
38
 
    char command[4];            /* Tcl command to invoke when a client
39
 
                                 * message for this protocol arrives.
40
 
                                 * The actual size of the structure varies
41
 
                                 * to accommodate the needs of the actual
42
 
                                 * command. THIS MUST BE THE LAST FIELD OF
43
 
                                 * THE STRUCTURE. */
 
36
    char command[4];            /* Tcl command to invoke when a client message
 
37
                                 * for this protocol arrives. The actual size
 
38
                                 * of the structure varies to accommodate the
 
39
                                 * needs of the actual command. THIS MUST BE
 
40
                                 * THE LAST FIELD OF THE STRUCTURE. */
44
41
#else
45
42
    LangCallback *command;
46
43
#endif
57
54
}
58
55
 
59
56
/*
 
57
 * Data for [wm attributes] command:
 
58
 */
 
59
typedef struct {
 
60
    double      alpha;          /* Transparency; 0.0=transparent, 1.0=opaque */
 
61
    int         topmost;        /* Flag: true=>stay-on-top */
 
62
    int         zoomed;         /* Flag: true=>maximized */
 
63
    int         fullscreen;     /* Flag: true=>fullscreen */
 
64
} WmAttributes;
 
65
 
 
66
typedef enum { 
 
67
    WMATT_ALPHA, WMATT_TOPMOST, WMATT_ZOOMED, WMATT_FULLSCREEN, 
 
68
    _WMATT_LAST_ATTRIBUTE
 
69
} WmAttribute;
 
70
 
 
71
static const char *WmAttributeNames[] = {
 
72
    "-alpha", "-topmost", "-zoomed", "-fullscreen",
 
73
    NULL
 
74
};
 
75
 
 
76
/*
60
77
 * A data structure of the following type holds window-manager-related
61
78
 * information for each top-level window in an application.
62
79
 */
63
80
 
64
81
typedef struct TkWmInfo {
65
 
    TkWindow *winPtr;           /* Pointer to main Tk information for
66
 
                                 * this window. */
 
82
    TkWindow *winPtr;           /* Pointer to main Tk information for this
 
83
                                 * window. */
67
84
    Window reparent;            /* If the window has been reparented, this
68
85
                                 * gives the ID of the ancestor of the window
69
 
                                 * that is a child of the root window (may
70
 
                                 * not be window's immediate parent).  If
71
 
                                 * the window isn't reparented, this has the
72
 
                                 * value None. */
73
 
    char *title;                /* Title to display in window caption.  If
74
 
                                 * NULL, use name of widget.  Malloced. */
75
 
    char *iconName;             /* Name to display in icon.  Malloced. */
76
 
    XWMHints hints;             /* Various pieces of information for
77
 
                                 * window manager. */
 
86
                                 * that is a child of the root window (may not
 
87
                                 * be window's immediate parent). If the
 
88
                                 * window isn't reparented, this has the value
 
89
                                 * None. */
 
90
    char *title;                /* Title to display in window caption. If
 
91
                                 * NULL, use name of widget. Malloced. */
 
92
    char *iconName;             /* Name to display in icon. Malloced. */
 
93
    XWMHints hints;             /* Various pieces of information for window
 
94
                                 * manager. */
78
95
    char *leaderName;           /* Path name of leader of window group
79
96
                                 * (corresponds to hints.window_group).
80
 
                                 * Malloc-ed.  Note:  this field doesn't
81
 
                                 * get updated if leader is destroyed. */
 
97
                                 * Malloc-ed. Note: this field doesn't get
 
98
                                 * updated if leader is destroyed. */
82
99
    TkWindow *masterPtr;        /* Master window for TRANSIENT_FOR property,
83
100
                                 * or NULL. */
84
 
    Tk_Window icon;             /* Window to use as icon for this window,
85
 
                                 * or NULL. */
 
101
    Tk_Window icon;             /* Window to use as icon for this window, or
 
102
                                 * NULL. */
86
103
    Tk_Image  iconImage;        /* Image used to generate Icon - or NULL */
87
104
    Tk_Window iconFor;          /* Window for which this window is icon, or
88
105
                                 * NULL if this isn't an icon for anyone. */
90
107
 
91
108
    /*
92
109
     * In order to support menubars transparently under X, each toplevel
93
 
     * window is encased in an additional window, called the wrapper,
94
 
     * that holds the toplevel and the menubar, if any.  The information
95
 
     * below is used to keep track of the wrapper and the menubar.
 
110
     * window is encased in an additional window, called the wrapper, that
 
111
     * holds the toplevel and the menubar, if any. The information below is
 
112
     * used to keep track of the wrapper and the menubar.
96
113
     */
97
114
 
98
115
    TkWindow *wrapperPtr;       /* Pointer to information about the wrapper.
99
 
                                 * This is the "real" toplevel window as
100
 
                                 * seen by the window manager. Although
101
 
                                 * this is an official Tk window, it
102
 
                                 * doesn't appear in the application's
103
 
                                 * window hierarchy.  NULL means that
104
 
                                 * the wrapper hasn't been created yet. */
105
 
    Tk_Window menubar;          /* Pointer to information about the
106
 
                                 * menubar, or NULL if there is no
107
 
                                 * menubar for this toplevel. */
 
116
                                 * This is the "real" toplevel window as seen
 
117
                                 * by the window manager. Although this is an
 
118
                                 * official Tk window, it doesn't appear in
 
119
                                 * the application's window hierarchy. NULL
 
120
                                 * means that the wrapper hasn't been created
 
121
                                 * yet. */
 
122
    Tk_Window menubar;          /* Pointer to information about the menubar,
 
123
                                 * or NULL if there is no menubar for this
 
124
                                 * toplevel. */
108
125
    int menuHeight;             /* Amount of vertical space needed for
109
 
                                 * menubar, measured in pixels.  If
110
 
                                 * menubar is non-NULL, this is >= 1 (X
111
 
                                 * servers don't like dimensions of 0). */
 
126
                                 * menubar, measured in pixels. If menubar is
 
127
                                 * non-NULL, this is >= 1 (X servers don't
 
128
                                 * like dimensions of 0). */
112
129
 
113
130
    /*
114
 
     * Information used to construct an XSizeHints structure for
115
 
     * the window manager:
 
131
     * Information used to construct an XSizeHints structure for the window
 
132
     * manager:
116
133
     */
117
134
 
118
 
    int sizeHintsFlags;         /* Flags word for XSizeHints structure.
119
 
                                 * If the PBaseSize flag is set then the
120
 
                                 * window is gridded;  otherwise it isn't
121
 
                                 * gridded. */
122
 
    int minWidth, minHeight;    /* Minimum dimensions of window, in
123
 
                                 * grid units, not pixels. */
124
 
    int maxWidth, maxHeight;    /* Maximum dimensions of window, in
125
 
                                 * grid units, not pixels. */
 
135
    int sizeHintsFlags;         /* Flags word for XSizeHints structure. If the
 
136
                                 * PBaseSize flag is set then the window is
 
137
                                 * gridded; otherwise it isn't gridded. */
 
138
    int minWidth, minHeight;    /* Minimum dimensions of window, in pixels or
 
139
                                 * grid units. */
 
140
    int maxWidth, maxHeight;    /* Maximum dimensions of window, in pixels or
 
141
                                 * grid units. 0 to default.*/
126
142
    Tk_Window gridWin;          /* Identifies the window that controls
127
 
                                 * gridding for this top-level, or NULL if
128
 
                                 * the top-level isn't currently gridded. */
129
 
    int widthInc, heightInc;    /* Increments for size changes (# pixels
130
 
                                 * per step). */
 
143
                                 * gridding for this top-level, or NULL if the
 
144
                                 * top-level isn't currently gridded. */
 
145
    int widthInc, heightInc;    /* Increments for size changes (# pixels per
 
146
                                 * step). */
131
147
    struct {
132
 
        int x;  /* numerator */
133
 
        int y;  /* denominator */
 
148
        int x;                  /* numerator */
 
149
        int y;                  /* denominator */
134
150
    } minAspect, maxAspect;     /* Min/max aspect ratios for window. */
135
151
    int reqGridWidth, reqGridHeight;
136
 
                                /* The dimensions of the window (in
137
 
                                 * grid units) requested through
138
 
                                 * the geometry manager. */
 
152
                                /* The dimensions of the window (in grid
 
153
                                 * units) requested through the geometry
 
154
                                 * manager. */
139
155
    int gravity;                /* Desired window gravity. */
140
156
 
141
157
    /*
142
158
     * Information used to manage the size and location of a window.
143
159
     */
144
160
 
145
 
    int width, height;          /* Desired dimensions of window, specified
146
 
                                 * in grid units.  These values are
147
 
                                 * set by the "wm geometry" command and by
148
 
                                 * ConfigureNotify events (for when wm
149
 
                                 * resizes window).  -1 means user hasn't
150
 
                                 * requested dimensions. */
 
161
    int width, height;          /* Desired dimensions of window, specified in
 
162
                                 * pixels or grid units. These values are set
 
163
                                 * by the "wm geometry" command and by
 
164
                                 * ConfigureNotify events (for when wm resizes
 
165
                                 * window). -1 means user hasn't requested
 
166
                                 * dimensions. */
151
167
    int x, y;                   /* Desired X and Y coordinates for window.
152
 
                                 * These values are set by "wm geometry",
153
 
                                 * plus by ConfigureNotify events (when wm
154
 
                                 * moves window).  These numbers are
155
 
                                 * different than the numbers stored in
156
 
                                 * winPtr->changes because (a) they could be
157
 
                                 * measured from the right or bottom edge
158
 
                                 * of the screen (see WM_NEGATIVE_X and
159
 
                                 * WM_NEGATIVE_Y flags) and (b) if the window
160
 
                                 * has been reparented then they refer to the
161
 
                                 * parent rather than the window itself. */
 
168
                                 * These values are set by "wm geometry", plus
 
169
                                 * by ConfigureNotify events (when wm moves
 
170
                                 * window). These numbers are different than
 
171
                                 * the numbers stored in winPtr->changes
 
172
                                 * because (a) they could be measured from the
 
173
                                 * right or bottom edge of the screen (see
 
174
                                 * WM_NEGATIVE_X and WM_NEGATIVE_Y flags) and
 
175
                                 * (b) if the window has been reparented then
 
176
                                 * they refer to the parent rather than the
 
177
                                 * window itself. */
162
178
    int parentWidth, parentHeight;
163
179
                                /* Width and height of reparent, in pixels
164
 
                                 * *including border*.  If window hasn't been
 
180
                                 * *including border*. If window hasn't been
165
181
                                 * reparented then these will be the outer
166
182
                                 * dimensions of the window, including
167
183
                                 * border. */
168
184
    int xInParent, yInParent;   /* Offset of wrapperPtr within reparent,
169
185
                                 * measured in pixels from upper-left outer
170
186
                                 * corner of reparent's border to upper-left
171
 
                                 * outer corner of wrapperPtr's border.  If
172
 
                                 * not reparented then these are zero. */
 
187
                                 * outer corner of wrapperPtr's border. If not
 
188
                                 * reparented then these are zero. */
173
189
    int configWidth, configHeight;
174
190
                                /* Dimensions passed to last request that we
175
191
                                 * issued to change geometry of the wrapper.
177
193
                                 * operations. */
178
194
 
179
195
    /*
180
 
     * Information about the virtual root window for this top-level,
181
 
     * if there is one.
 
196
     * Information about the virtual root window for this top-level, if there
 
197
     * is one.
182
198
     */
183
199
 
184
 
    Window vRoot;               /* Virtual root window for this top-level,
185
 
                                 * or None if there is no virtual root
186
 
                                 * window (i.e. just use the screen's root). */
 
200
    Window vRoot;               /* Virtual root window for this top-level, or
 
201
                                 * None if there is no virtual root window
 
202
                                 * (i.e. just use the screen's root). */
187
203
    int vRootX, vRootY;         /* Position of the virtual root inside the
188
 
                                 * root window.  If the WM_VROOT_OFFSET_STALE
 
204
                                 * root window. If the WM_VROOT_OFFSET_STALE
189
205
                                 * flag is set then this information may be
190
206
                                 * incorrect and needs to be refreshed from
191
 
                                 * the X server.  If vRoot is None then these
 
207
                                 * the X server. If vRoot is None then these
192
208
                                 * values are both 0. */
193
 
    int vRootWidth, vRootHeight;/* Dimensions of the virtual root window.
194
 
                                 * If vRoot is None, gives the dimensions
195
 
                                 * of the containing screen.  This information
196
 
                                 * is never stale, even though vRootX and
197
 
                                 * vRootY can be. */
 
209
    int vRootWidth, vRootHeight;/* Dimensions of the virtual root window. If
 
210
                                 * vRoot is None, gives the dimensions of the
 
211
                                 * containing screen. This information is
 
212
                                 * never stale, even though vRootX and vRootY
 
213
                                 * can be. */
198
214
 
199
215
    /*
200
216
     * Miscellaneous information.
201
217
     */
202
218
 
203
 
    ProtocolHandler *protPtr;   /* First in list of protocol handlers for
204
 
                                 * this window (NULL means none). */
 
219
    WmAttributes attributes;    /* Current state of [wm attributes] */
 
220
    WmAttributes reqState;      /* Requested state of [wm attributes] */
 
221
    ProtocolHandler *protPtr;   /* First in list of protocol handlers for this
 
222
                                 * window (NULL means none). */
205
223
#ifndef _LANG
206
224
    int cmdArgc;                /* Number of elements in cmdArgv below. */
207
 
    CONST char **cmdArgv;       /* Array of strings to store in the
208
 
                                 * WM_COMMAND property.  NULL means nothing
209
 
                                 * available. */
 
225
    CONST char **cmdArgv;       /* Array of strings to store in the WM_COMMAND
 
226
                                 * property. NULL means nothing available. */
210
227
#else
211
228
    Tcl_Obj *cmdArg;            /* Object holding list - to keep strings live */
212
229
#endif
214
231
                                 * property, or NULL. */
215
232
    int flags;                  /* Miscellaneous flags, defined below. */
216
233
    int numTransients;          /* number of transients on this window */
 
234
    int iconDataSize;           /* size of iconphoto image data */
 
235
    unsigned char *iconDataPtr; /* iconphoto image data, if set */
217
236
    struct TkWmInfo *nextPtr;   /* Next in list of all top-level windows. */
218
237
} WmInfo;
219
238
 
220
239
/*
221
240
 * Flag values for WmInfo structures:
222
241
 *
223
 
 * WM_NEVER_MAPPED -            non-zero means window has never been
224
 
 *                              mapped;  need to update all info when
225
 
 *                              window is first mapped.
 
242
 * WM_NEVER_MAPPED -            non-zero means window has never been mapped;
 
243
 *                              need to update all info when window is first
 
244
 *                              mapped.
226
245
 * WM_UPDATE_PENDING -          non-zero means a call to UpdateGeometryInfo
227
 
 *                              has already been scheduled for this
228
 
 *                              window;  no need to schedule another one.
 
246
 *                              has already been scheduled for this window;
 
247
 *                              no need to schedule another one.
229
248
 * WM_NEGATIVE_X -              non-zero means x-coordinate is measured in
230
 
 *                              pixels from right edge of screen, rather
231
 
 *                              than from left edge.
 
249
 *                              pixels from right edge of screen, rather than
 
250
 *                              from left edge.
232
251
 * WM_NEGATIVE_Y -              non-zero means y-coordinate is measured in
233
252
 *                              pixels up from bottom of screen, rather than
234
253
 *                              down from top.
239
258
 * WM_VROOT_OFFSET_STALE -      non-zero means that (x,y) offset information
240
259
 *                              about the virtual root window is stale and
241
260
 *                              needs to be fetched fresh from the X server.
242
 
 * WM_ABOUT_TO_MAP -            non-zero means that the window is about to
243
 
 *                              be mapped by TkWmMapWindow.  This is used
244
 
 *                              by UpdateGeometryInfo to modify its behavior.
245
 
 * WM_MOVE_PENDING -            non-zero means the application has requested
246
 
 *                              a new position for the window, but it hasn't
247
 
 *                              been reflected through the window manager
248
 
 *                              yet.
249
 
 * WM_COLORMAPS_EXPLICIT -      non-zero means the colormap windows were
250
 
 *                              set explicitly via "wm colormapwindows".
 
261
 * WM_ABOUT_TO_MAP -            non-zero means that the window is about to be
 
262
 *                              mapped by TkWmMapWindow. This is used by
 
263
 *                              UpdateGeometryInfo to modify its behavior.
 
264
 * WM_MOVE_PENDING -            non-zero means the application has requested a
 
265
 *                              new position for the window, but it hasn't
 
266
 *                              been reflected through the window manager yet.
 
267
 * WM_COLORMAPS_EXPLICIT -      non-zero means the colormap windows were set
 
268
 *                              explicitly via "wm colormapwindows".
251
269
 * WM_ADDED_TOPLEVEL_COLORMAP - non-zero means that when "wm colormapwindows"
252
270
 *                              was called the top-level itself wasn't
253
 
 *                              specified, so we added it implicitly at
254
 
 *                              the end of the list.
 
271
 *                              specified, so we added it implicitly at the
 
272
 *                              end of the list.
255
273
 * WM_WIDTH_NOT_RESIZABLE -     non-zero means that we're not supposed to
256
274
 *                              allow the user to change the width of the
257
 
 *                              window (controlled by "wm resizable"
258
 
 *                              command).
 
275
 *                              window (controlled by "wm resizable" command).
259
276
 * WM_HEIGHT_NOT_RESIZABLE -    non-zero means that we're not supposed to
260
277
 *                              allow the user to change the height of the
261
 
 *                              window (controlled by "wm resizable"
262
 
 *                              command).
 
278
 *                              window (controlled by "wm resizable" command).
263
279
 * WM_WITHDRAWN -               non-zero means that this window has explicitly
264
280
 *                              been withdrawn. If it's a transient, it should
265
281
 *                              not mirror state changes in the master.
278
294
#define WM_ADDED_TOPLEVEL_COLORMAP      0x800
279
295
#define WM_WIDTH_NOT_RESIZABLE          0x1000
280
296
#define WM_HEIGHT_NOT_RESIZABLE         0x2000
281
 
#define WM_WITHDRAWN                    0x4000
 
297
#define WM_WITHDRAWN                    0x4000
282
298
 
283
299
/*
284
 
 * This module keeps a list of all top-level windows, primarily to
285
 
 * simplify the job of Tk_CoordsToWindow.  The list is called
286
 
 * firstWmPtr and is stored in the TkDisplay structure.
 
300
 * This module keeps a list of all top-level windows, primarily to simplify
 
301
 * the job of Tk_CoordsToWindow. The list is called firstWmPtr and is stored
 
302
 * in the TkDisplay structure.
287
303
 */
288
304
 
289
305
/*
291
307
 * management of top-level and menubar windows.
292
308
 */
293
309
 
294
 
static void             TopLevelReqProc _ANSI_ARGS_((ClientData dummy,
295
 
                            Tk_Window tkwin));
296
 
static  void            TopLevelLostSlaveProc _ANSI_ARGS_((ClientData clientData,
 
310
static void             TopLevelReqProc(ClientData dummy, Tk_Window tkwin);
 
311
static void             TopLevelLostSlaveProc _ANSI_ARGS_((ClientData clientData,
297
312
                            Tk_Window tkwin));
298
313
 
299
314
 
302
317
    TopLevelReqProc,                    /* requestProc */
303
318
    TopLevelLostSlaveProc,              /* lostSlaveProc */
304
319
};
305
 
 
306
320
/*
307
321
 * Forward declarations for procedures defined in this file:
308
322
 */
319
333
static Tk_GeomMgr menubarMgrType = {
320
334
    "menubar",                          /* name */
321
335
    MenubarReqProc,                     /* requestProc */
322
 
    (Tk_GeomLostSlaveProc *) NULL,      /* lostSlaveProc */
 
336
    NULL,                               /* lostSlaveProc */
323
337
};
324
338
 
325
339
/*
332
346
    WmInfo *wmInfoPtr;
333
347
    int type;                   /* We only care about this type of event. */
334
348
    XEvent *eventPtr;           /* Where to store the event when it's found. */
335
 
    int foundEvent;             /* Non-zero means that an event of the
336
 
                                 * desired type has been found. */
 
349
    int foundEvent;             /* Non-zero means that an event of the desired
 
350
                                 * type has been found. */
337
351
} WaitRestrictInfo;
338
352
 
339
353
/*
340
 
 * Forward declarations for procedures defined in this file:
 
354
 * Forward declarations for functions defined in this file:
341
355
 */
342
356
 
343
357
static int              ComputeReparentGeometry _ANSI_ARGS_((WmInfo *wmPtr));
354
368
                            XReparentEvent *eventPtr));
355
369
static void             TkWmStackorderToplevelWrapperMap _ANSI_ARGS_((
356
370
                            TkWindow *winPtr,
 
371
                            Display *display,
357
372
                            Tcl_HashTable *reparentTable));
358
373
static void             TopLevelEventProc _ANSI_ARGS_((ClientData clientData,
359
374
                            XEvent *eventPtr));
363
378
static void             UpdateGeometryInfo _ANSI_ARGS_((
364
379
                            ClientData clientData));
365
380
static void             UpdateHints _ANSI_ARGS_((TkWindow *winPtr));
366
 
static void             UpdateSizeHints _ANSI_ARGS_((TkWindow *winPtr));
 
381
static void             UpdateSizeHints _ANSI_ARGS_((TkWindow *winPtr,
 
382
                            int newWidth,
 
383
                            int newHeight));
 
384
static void             UpdateTitle(TkWindow *winPtr);
 
385
static void             UpdatePhotoIcon(TkWindow *winPtr);
367
386
static void             UpdateVRootGeometry _ANSI_ARGS_((WmInfo *wmPtr));
368
387
static void             UpdateWmProtocols _ANSI_ARGS_((WmInfo *wmPtr));
 
388
static void             SetNetWmState(TkWindow*, const char *atomName, int on);
 
389
static void             CheckNetWmState(WmInfo *, Atom *atoms, int numAtoms);
 
390
static void             UpdateNetWmState(WmInfo *);
369
391
static void             WaitForConfigureNotify _ANSI_ARGS_((TkWindow *winPtr,
370
392
                            unsigned long serial));
371
393
static int              WaitForEvent _ANSI_ARGS_((Display *display,
375
397
 
376
398
static void             UnmanageGeometry _ANSI_ARGS_((Tk_Window tkwin));
377
399
 
 
400
static int              WmProtocolCmd(Tk_Window tkwin, TkWindow *winPtr,
 
401
                            Tcl_Interp *interp, int objc,
 
402
                            Tcl_Obj *CONST objv[]);
 
403
static int              WmResizableCmd(Tk_Window tkwin, TkWindow *winPtr,
 
404
                            Tcl_Interp *interp, int objc,
 
405
                            Tcl_Obj *CONST objv[]);
 
406
static int              WmSizefromCmd(Tk_Window tkwin, TkWindow *winPtr,
 
407
                            Tcl_Interp *interp, int objc,
 
408
                            Tcl_Obj *CONST objv[]);
 
409
static int              WmStackorderCmd(Tk_Window tkwin, TkWindow *winPtr,
 
410
                            Tcl_Interp *interp, int objc,
 
411
                            Tcl_Obj *CONST objv[]);
 
412
static int              WmStateCmd(Tk_Window tkwin, TkWindow *winPtr,
 
413
                            Tcl_Interp *interp, int objc,
 
414
                            Tcl_Obj *CONST objv[]);
 
415
static int              WmTitleCmd(Tk_Window tkwin, TkWindow *winPtr,
 
416
                            Tcl_Interp *interp, int objc,
 
417
                            Tcl_Obj *CONST objv[]);
 
418
static int              WmTransientCmd(Tk_Window tkwin, TkWindow *winPtr,
 
419
                            Tcl_Interp *interp, int objc,
 
420
                            Tcl_Obj *CONST objv[]);
 
421
static int              WmWithdrawCmd(Tk_Window tkwin, TkWindow *winPtr,
 
422
                            Tcl_Interp *interp, int objc,
 
423
                            Tcl_Obj *CONST objv[]);
 
424
static void             WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr);
378
425
static Tk_RestrictAction
379
426
                        WaitRestrictProc _ANSI_ARGS_((ClientData clientData,
380
427
                            XEvent *eventPtr));
434
481
static int              WmIconnameCmd _ANSI_ARGS_((Tk_Window tkwin,
435
482
                            TkWindow *winPtr, Tcl_Interp *interp, int objc,
436
483
                            Tcl_Obj *CONST objv[]));
 
484
static int              WmIconphotoCmd(Tk_Window tkwin, TkWindow *winPtr,
 
485
                            Tcl_Interp *interp, int objc,
 
486
                            Tcl_Obj *CONST objv[]);
437
487
static int              WmIconpositionCmd _ANSI_ARGS_((Tk_Window tkwin,
438
488
                            TkWindow *winPtr, Tcl_Interp *interp, int objc,
439
489
                            Tcl_Obj *CONST objv[]));
490
540
 *
491
541
 * TkWmCleanup --
492
542
 *
493
 
 *      This procedure is invoked to cleanup remaining wm resources
494
 
 *      associated with a display.
 
543
 *      This function is invoked to cleanup remaining wm resources associated
 
544
 *      with a display.
495
545
 *
496
546
 * Results:
497
547
 *      None.
502
552
 *--------------------------------------------------------------
503
553
 */
504
554
 
505
 
 
506
555
static void
507
556
TkWmFreeCmd(wmPtr)
508
557
WmInfo *wmPtr;
513
562
    }
514
563
}
515
564
 
516
 
void TkWmCleanup(dispPtr)
517
 
    TkDisplay *dispPtr;
 
565
void TkWmCleanup(
 
566
    TkDisplay *dispPtr)
518
567
{
519
568
    WmInfo *wmPtr, *nextPtr;
 
569
 
520
570
    for (wmPtr = dispPtr->firstWmPtr; wmPtr != NULL; wmPtr = nextPtr) {
521
571
        /*
522
 
         * We can't assume we have access to winPtr's anymore, so some
523
 
         * cleanup requiring winPtr data is avoided.
 
572
         * We can't assume we have access to winPtr's anymore, so some cleanup
 
573
         * requiring winPtr data is avoided.
524
574
         */
 
575
 
525
576
        nextPtr = wmPtr->nextPtr;
526
577
        if (wmPtr->title != NULL) {
527
578
            ckfree(wmPtr->title);
529
580
        if (wmPtr->iconName != NULL) {
530
581
            ckfree(wmPtr->iconName);
531
582
        }
 
583
        if (wmPtr->iconDataPtr != NULL) {
 
584
            ckfree((char *)wmPtr->iconDataPtr);
 
585
        }
532
586
        if (wmPtr->leaderName != NULL) {
533
587
            ckfree(wmPtr->leaderName);
534
588
        }
557
611
        }
558
612
        ckfree((char *) wmPtr);
559
613
    }
 
614
    if (dispPtr->iconDataPtr != NULL) {
 
615
        ckfree((char *)dispPtr->iconDataPtr);
 
616
        dispPtr->iconDataPtr = NULL;
 
617
    }
560
618
}
561
619
 
562
620
/*
564
622
 *
565
623
 * TkWmNewWindow --
566
624
 *
567
 
 *      This procedure is invoked whenever a new top-level
568
 
 *      window is created.  Its job is to initialize the WmInfo
569
 
 *      structure for the window.
 
625
 *      This function is invoked whenever a new top-level window is created.
 
626
 *      Its job is to initialize the WmInfo structure for the window.
570
627
 *
571
628
 * Results:
572
629
 *      None.
578
635
 */
579
636
 
580
637
void
581
 
TkWmNewWindow(winPtr)
582
 
    TkWindow *winPtr;           /* Newly-created top-level window. */
 
638
TkWmNewWindow(
 
639
    TkWindow *winPtr)           /* Newly-created top-level window. */
583
640
{
584
641
    register WmInfo *wmPtr;
585
642
    TkDisplay *dispPtr = winPtr->dispPtr;
598
655
    wmPtr->hints.icon_x = wmPtr->hints.icon_y = 0;
599
656
    wmPtr->hints.icon_mask = None;
600
657
    wmPtr->hints.window_group = None;
 
658
 
 
659
    /*
 
660
     * Initialize attributes.
 
661
     */
 
662
    wmPtr->attributes.alpha = 1.0;
 
663
    wmPtr->attributes.topmost = 0;
 
664
    wmPtr->attributes.zoomed = 0;
 
665
    wmPtr->attributes.fullscreen = 0;
 
666
    wmPtr->reqState = wmPtr->attributes;
 
667
 
 
668
    /*
 
669
     * Default the maximum dimensions to the size of the display, minus a
 
670
     * guess about how space is needed for window manager decorations.
 
671
     */
 
672
 
 
673
    wmPtr->gridWin = NULL;
601
674
    wmPtr->minWidth = wmPtr->minHeight = 1;
602
 
 
603
 
    /*
604
 
     * Default the maximum dimensions to the size of the display, minus
605
 
     * a guess about how space is needed for window manager decorations.
606
 
     */
607
 
 
 
675
    wmPtr->maxWidth = wmPtr->maxHeight = 0;
608
676
    wmPtr->widthInc = wmPtr->heightInc = 1;
609
677
    wmPtr->minAspect.x = wmPtr->minAspect.y = 1;
610
678
    wmPtr->maxAspect.x = wmPtr->maxAspect.y = 1;
629
697
    UpdateVRootGeometry(wmPtr);
630
698
 
631
699
    /*
632
 
     * Arrange for geometry requests to be reflected from the window
633
 
     * to the window manager.
 
700
     * Arrange for geometry requests to be reflected from the window to the
 
701
     * window manager.
634
702
     */
635
703
 
636
704
    Tk_ManageGeometry((Tk_Window) winPtr, &wmMgrType, (ClientData) 0);
641
709
 *
642
710
 * TkWmMapWindow --
643
711
 *
644
 
 *      This procedure is invoked to map a top-level window.  This
645
 
 *      module gets a chance to update all window-manager-related
646
 
 *      information in properties before the window manager sees
647
 
 *      the map event and checks the properties.  It also gets to
648
 
 *      decide whether or not to even map the window after all.
 
712
 *      This function is invoked to map a top-level window. This module gets a
 
713
 *      chance to update all window-manager-related information in properties
 
714
 *      before the window manager sees the map event and checks the
 
715
 *      properties. It also gets to decide whether or not to even map the
 
716
 *      window after all.
649
717
 *
650
718
 * Results:
651
719
 *      None.
652
720
 *
653
721
 * Side effects:
654
 
 *      Properties of winPtr may get updated to provide up-to-date
655
 
 *      information to the window manager.  The window may also get
656
 
 *      mapped, but it may not be if this procedure decides that
657
 
 *      isn't appropriate (e.g. because the window is withdrawn).
 
722
 *      Properties of winPtr may get updated to provide up-to-date information
 
723
 *      to the window manager. The window may also get mapped, but it may not
 
724
 *      be if this function decides that isn't appropriate (e.g. because the
 
725
 *      window is withdrawn).
658
726
 *
659
727
 *--------------------------------------------------------------
660
728
 */
661
729
 
662
730
void
663
 
TkWmMapWindow(winPtr)
664
 
    TkWindow *winPtr;           /* Top-level window that's about to
665
 
                                 * be mapped. */
 
731
TkWmMapWindow(
 
732
    TkWindow *winPtr)           /* Top-level window that's about to be
 
733
                                 * mapped. */
666
734
{
667
735
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
668
736
    XTextProperty textProp;
669
 
    Tk_Uid string;
670
737
 
671
738
    if (wmPtr->flags & WM_NEVER_MAPPED) {
672
739
        Tcl_DString ds;
674
741
        wmPtr->flags &= ~WM_NEVER_MAPPED;
675
742
 
676
743
        /*
677
 
         * This is the first time this window has ever been mapped.
678
 
         * First create the wrapper window that provides space for a
679
 
         * menubar.
 
744
         * This is the first time this window has ever been mapped. First
 
745
         * create the wrapper window that provides space for a menubar.
680
746
         */
681
747
 
682
748
        if (wmPtr->wrapperPtr == NULL) {
684
750
        }
685
751
 
686
752
        /*
687
 
         * Store all the window-manager-related information for the
688
 
         * window.
 
753
         * Store all the window-manager-related information for the window.
689
754
         */
690
755
 
691
 
        string = (wmPtr->title != NULL) ? wmPtr->title : winPtr->nameUid;
692
 
        Tcl_UtfToExternalDString(NULL, string, -1, &ds);
693
 
        string = Tcl_DStringValue(&ds);
 
756
#if 0
 
757
REMOVED >>>> ORIGINAL tkUnixWm.c#1
 
758
        if (XStringListToTextProperty(&(Tcl_DStringValue(&ds)), 1,
 
759
                &textProp)  != 0) {
 
760
            XSetWMName(winPtr->display, wmPtr->wrapperPtr->window, &textProp);
 
761
            XFree((char *) textProp.value);
 
762
        }
 
763
        Tcl_DStringFree(&ds);
 
764
 
 
765
REMOVED ==== THEIRS tkUnixWm.c#3
 
766
REMOVED ==== YOURS tkUnixWm.c
694
767
        if (XStringListToTextProperty((char **)&string, 1,
695
768
                &textProp)  != 0) {
696
769
            XSetWMName(winPtr->display, wmPtr->wrapperPtr->window, &textProp);
698
771
        }
699
772
        Tcl_DStringFree(&ds);
700
773
 
 
774
REMOVED <<<<
 
775
#endif
701
776
        TkWmSetClass(winPtr);
702
 
 
703
 
        if (wmPtr->iconName != NULL) {
704
 
            Tcl_UtfToExternalDString(NULL, wmPtr->iconName, -1, &ds);
705
 
            XSetIconName(winPtr->display, wmPtr->wrapperPtr->window,
706
 
                    Tcl_DStringValue(&ds));
707
 
            Tcl_DStringFree(&ds);
708
 
        }
 
777
        UpdateTitle(winPtr);
 
778
        UpdatePhotoIcon(winPtr);
709
779
 
710
780
        if (wmPtr->masterPtr != NULL) {
711
781
            /*
713
783
             */
714
784
 
715
785
            if (!Tk_IsMapped(wmPtr->masterPtr)) {
716
 
                wmPtr->withdrawn = 1;
717
 
                wmPtr->hints.initial_state = WithdrawnState;
 
786
                wmPtr->withdrawn = 1;
 
787
                wmPtr->hints.initial_state = WithdrawnState;
718
788
            } else {
719
 
                XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
720
 
                        wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window);
 
789
                XSetTransientForHint(winPtr->display,
 
790
                        wmPtr->wrapperPtr->window,
 
791
                        wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window);
721
792
            }
722
793
        }
723
794
 
745
816
    }
746
817
    if (wmPtr->iconFor != NULL) {
747
818
        /*
748
 
         * This window is an icon for somebody else.  Make sure that
749
 
         * the geometry is up-to-date, then return without mapping
750
 
         * the window.
 
819
         * This window is an icon for somebody else. Make sure that the
 
820
         * geometry is up-to-date, then return without mapping the window.
751
821
         */
752
822
 
753
823
        if (wmPtr->flags & WM_UPDATE_PENDING) {
764
834
    wmPtr->flags &= ~WM_ABOUT_TO_MAP;
765
835
 
766
836
    /*
 
837
     * Update _NET_WM_STATE hints:
 
838
     */
 
839
    UpdateNetWmState(wmPtr);
 
840
 
 
841
    /*
767
842
     * Map the window, then wait to be sure that the window manager has
768
843
     * processed the map operation.
769
844
     */
779
854
 *
780
855
 * TkWmUnmapWindow --
781
856
 *
782
 
 *      This procedure is invoked to unmap a top-level window.  The
783
 
 *      only thing it does special is to wait for the window actually
784
 
 *      to be unmapped.
 
857
 *      This function is invoked to unmap a top-level window. The only thing
 
858
 *      it does special is to wait for the window actually to be unmapped.
785
859
 *
786
860
 * Results:
787
861
 *      None.
793
867
 */
794
868
 
795
869
void
796
 
TkWmUnmapWindow(winPtr)
797
 
    TkWindow *winPtr;           /* Top-level window that's about to
798
 
                                 * be mapped. */
 
870
TkWmUnmapWindow(
 
871
    TkWindow *winPtr)           /* Top-level window that's about to be
 
872
                                 * mapped. */
799
873
{
800
874
    /*
801
 
     * It seems to be important to wait after unmapping a top-level
802
 
     * window until the window really gets unmapped.  I don't completely
803
 
     * understand all the interactions with the window manager, but if
804
 
     * we go on without waiting, and if the window is then mapped again
805
 
     * quickly, events seem to get lost so that we think the window isn't
806
 
     * mapped when in fact it is mapped.  I suspect that this has something
807
 
     * to do with the window manager filtering Map events (and possily not
808
 
     * filtering Unmap events?).
 
875
     * It seems to be important to wait after unmapping a top-level window
 
876
     * until the window really gets unmapped. I don't completely understand
 
877
     * all the interactions with the window manager, but if we go on without
 
878
     * waiting, and if the window is then mapped again quickly, events seem to
 
879
     * get lost so that we think the window isn't mapped when in fact it is
 
880
     * mapped. I suspect that this has something to do with the window manager
 
881
     * filtering Map events (and possily not filtering Unmap events?).
809
882
     */
 
883
 
810
884
    XUnmapWindow(winPtr->display, winPtr->wmInfoPtr->wrapperPtr->window);
811
885
    WaitForMapNotify(winPtr, 0);
812
886
}
817
891
 *
818
892
 * TkWmDeadWindow --
819
893
 *
820
 
 *      This procedure is invoked when a top-level window is
821
 
 *      about to be deleted.  It cleans up the wm-related data
822
 
 *      structures for the window.
 
894
 *      This function is invoked when a top-level window is about to be
 
895
 *      deleted. It cleans up the wm-related data structures for the window.
823
896
 *
824
897
 * Results:
825
898
 *      None.
832
905
 
833
906
 
834
907
void
835
 
TkWmDeadWindow(winPtr)
836
 
    TkWindow *winPtr;           /* Top-level window that's being deleted. */
 
908
TkWmDeadWindow(
 
909
    TkWindow *winPtr)           /* Top-level window that's being deleted. */
837
910
{
838
911
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
839
912
    WmInfo *wmPtr2;
847
920
        register WmInfo *prevPtr;
848
921
 
849
922
        for (prevPtr = (WmInfo *) winPtr->dispPtr->firstWmPtr; ;
850
 
                prevPtr = prevPtr->nextPtr) {
 
923
                prevPtr = prevPtr->nextPtr) {
851
924
            if (prevPtr == NULL) {
852
 
                panic("couldn't unlink window in TkWmDeadWindow");
 
925
                Tcl_Panic("couldn't unlink window in TkWmDeadWindow");
853
926
            }
854
927
            if (prevPtr->nextPtr == wmPtr) {
855
928
                prevPtr->nextPtr = wmPtr->nextPtr;
863
936
    if (wmPtr->iconName != NULL) {
864
937
        ckfree(wmPtr->iconName);
865
938
    }
 
939
    if (wmPtr->iconDataPtr != NULL) {
 
940
        ckfree((char *)wmPtr->iconDataPtr);
 
941
    }
866
942
 
867
943
    if (wmPtr->hints.icon_pixmap) {
868
944
        if (wmPtr->iconImage) {
898
974
    }
899
975
    if (wmPtr->wrapperPtr != NULL) {
900
976
        /*
901
 
         * The rest of Tk doesn't know that we reparent the toplevel
902
 
         * inside the wrapper, so reparent it back out again before
903
 
         * deleting the wrapper; otherwise the toplevel will get deleted
904
 
         * twice (once implicitly by the deletion of the wrapper).
 
977
         * The rest of Tk doesn't know that we reparent the toplevel inside
 
978
         * the wrapper, so reparent it back out again before deleting the
 
979
         * wrapper; otherwise the toplevel will get deleted twice (once
 
980
         * implicitly by the deletion of the wrapper).
905
981
         */
906
982
 
907
983
        XUnmapWindow(winPtr->display, winPtr->window);
929
1005
    if (wmPtr->flags & WM_UPDATE_PENDING) {
930
1006
        Tcl_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr);
931
1007
    }
 
1008
 
932
1009
    /*
933
1010
     * Reset all transient windows whose master is the dead window.
934
1011
     */
935
1012
 
936
1013
    for (wmPtr2 = winPtr->dispPtr->firstWmPtr; wmPtr2 != NULL;
937
 
         wmPtr2 = wmPtr2->nextPtr) {
 
1014
            wmPtr2 = wmPtr2->nextPtr) {
938
1015
        if (wmPtr2->masterPtr == winPtr) {
939
1016
            wmPtr->numTransients--;
940
1017
            Tk_DeleteEventHandler((Tk_Window) wmPtr2->masterPtr,
941
 
                    StructureNotifyMask,
942
 
                    WmWaitMapProc, (ClientData) wmPtr2->winPtr);
 
1018
                    StructureNotifyMask,
 
1019
                    WmWaitMapProc, (ClientData) wmPtr2->winPtr);
943
1020
            wmPtr2->masterPtr = NULL;
944
1021
            if (!(wmPtr2->flags & WM_NEVER_MAPPED)) {
945
 
                XSetTransientForHint(wmPtr2->winPtr->display,
946
 
                        wmPtr2->wrapperPtr->window, None);
947
 
                /* FIXME: Need a call like Win32's UpdateWrapper() so
948
 
                   we can recreate the wrapper and get rid of the
949
 
                   transient window decorations. */
 
1022
                XDeleteProperty(winPtr->display, wmPtr2->wrapperPtr->window,
 
1023
                        Tk_InternAtom((Tk_Window) winPtr, "WM_TRANSIENT_FOR"));
 
1024
 
 
1025
                /*
 
1026
                 * FIXME: Need a call like Win32's UpdateWrapper() so we can
 
1027
                 * recreate the wrapper and get rid of the transient window
 
1028
                 * decorations.
 
1029
                 */
950
1030
            }
951
1031
        }
952
1032
    }
953
 
    if (wmPtr->numTransients != 0)
954
 
        panic("numTransients should be 0");
 
1033
    if (wmPtr->numTransients != 0) {
 
1034
        Tcl_Panic("numTransients should be 0");
 
1035
    }
955
1036
 
956
1037
    if (wmPtr->masterPtr != NULL) {
957
1038
        wmPtr2 = wmPtr->masterPtr->wmInfoPtr;
 
1039
 
958
1040
        /*
959
 
         * If we had a master, tell them that we aren't tied
960
 
         * to them anymore
 
1041
         * If we had a master, tell them that we aren't tied to them anymore
961
1042
         */
 
1043
 
962
1044
        if (wmPtr2 != NULL) {
963
1045
            wmPtr2->numTransients--;
964
1046
        }
965
1047
        Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
966
 
                StructureNotifyMask,
967
 
                WmWaitMapProc, (ClientData) winPtr);
 
1048
                StructureNotifyMask, WmWaitMapProc, (ClientData) winPtr);
968
1049
        wmPtr->masterPtr = NULL;
969
1050
    }
970
1051
    ckfree((char *) wmPtr);
976
1057
 *
977
1058
 * TkWmSetClass --
978
1059
 *
979
 
 *      This procedure is invoked whenever a top-level window's
980
 
 *      class is changed.  If the window has been mapped then this
981
 
 *      procedure updates the window manager property for the
982
 
 *      class.  If the window hasn't been mapped, the update is
983
 
 *      deferred until just before the first mapping.
 
1060
 *      This function is invoked whenever a top-level window's class is
 
1061
 *      changed. If the window has been mapped then this function updates the
 
1062
 *      window manager property for the class. If the window hasn't been
 
1063
 *      mapped, the update is deferred until just before the first mapping.
984
1064
 *
985
1065
 * Results:
986
1066
 *      None.
992
1072
 */
993
1073
 
994
1074
void
995
 
TkWmSetClass(winPtr)
996
 
    TkWindow *winPtr;           /* Newly-created top-level window. */
 
1075
TkWmSetClass(
 
1076
    TkWindow *winPtr)           /* Newly-created top-level window. */
997
1077
{
998
1078
    if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
999
1079
        return;
1048
1128
 * Tk_WmObjCmd --
1049
1129
 * Tk_WmCmd --
1050
1130
 *
1051
 
 *      This procedure is invoked to process the "wm" Tcl command.
1052
 
 *      See the user documentation for details on what it does.
1053
 
 *
1054
 
 * Results:
1055
 
 *      A standard Tcl result.
1056
 
 *
1057
 
 * Side effects:
1058
 
 *      See the user documentation.
 
1131
 *      This function is invoked to process the "wm" Tcl command. 
1059
1132
 *
1060
1133
 *----------------------------------------------------------------------
1061
1134
 */
1062
1135
/* ARGSUSED */
1063
1136
int
1064
 
Tk_WmObjCmd(clientData, interp, objc, objv)
1065
 
    ClientData clientData;      /* Main window associated with
1066
 
                                 * interpreter. */
1067
 
    Tcl_Interp *interp;         /* Current interpreter. */
1068
 
    int objc;                   /* Number of arguments. */
1069
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1137
Tk_WmObjCmd(
 
1138
    ClientData clientData,      /* Main window associated with interpreter. */
 
1139
    Tcl_Interp *interp,         /* Current interpreter. */
 
1140
    int objc,                   /* Number of arguments. */
 
1141
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1070
1142
{
1071
1143
    Tk_Window tkwin = (Tk_Window) clientData;
1072
1144
    static CONST char *optionStrings[] = {
1073
1145
        "aspect", "attributes", "capture", "client", "colormapwindows",
1074
1146
        "command", "deiconify", "focusmodel", "frame",
1075
1147
        "geometry", "grid", "group", "iconbitmap",
1076
 
        "iconify", "iconimage", "iconmask", "iconname", "iconposition",
 
1148
        "iconify", "iconimage", "iconmask", "iconname",
 
1149
        "iconphoto", "iconposition",
1077
1150
        "iconwindow", "maxsize", "minsize", "overrideredirect",
1078
 
        "positionfrom", "protocol", "release", "resizable", "sizefrom",
1079
 
        "stackorder", "state", "title", "transient",
1080
 
        "withdraw", "wrapper", (char *) NULL };
 
1151
        "positionfrom", "protocol", "release", "resizable", "sizefrom",
 
1152
        "stackorder", "state", "title", "transient",
 
1153
        "withdraw", "wrapper", NULL };
1081
1154
    enum options {
1082
1155
        WMOPT_ASPECT, WMOPT_ATTRIBUTES, WMOPT_CAPTURE, WMOPT_CLIENT, WMOPT_COLORMAPWINDOWS,
1083
1156
        WMOPT_COMMAND, WMOPT_DEICONIFY, WMOPT_FOCUSMODEL, WMOPT_FRAME,
1084
1157
        WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP, WMOPT_ICONBITMAP,
1085
 
        WMOPT_ICONIFY, WMOPT_ICONIMAGE, WMOPT_ICONMASK, WMOPT_ICONNAME, WMOPT_ICONPOSITION,
 
1158
        WMOPT_ICONIFY, WMOPT_ICONIMAGE, WMOPT_ICONMASK, WMOPT_ICONNAME,
 
1159
        WMOPT_ICONPHOTO, WMOPT_ICONPOSITION,
1086
1160
        WMOPT_ICONWINDOW, WMOPT_MAXSIZE, WMOPT_MINSIZE, WMOPT_OVERRIDEREDIRECT,
1087
1161
        WMOPT_POSITIONFROM, WMOPT_PROTOCOL, WMOPT_RELEASE, WMOPT_RESIZABLE, WMOPT_SIZEFROM,
1088
1162
        WMOPT_STACKORDER, WMOPT_STATE, WMOPT_TITLE, WMOPT_TRANSIENT,
1094
1168
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
1095
1169
 
1096
1170
    if (objc < 2) {
1097
 
        wrongNumArgs:
 
1171
    wrongNumArgs:
1098
1172
        Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?");
1099
1173
        return TCL_ERROR;
1100
1174
    }
1103
1177
    if ((argv1[0] == 't') && (strncmp(argv1, "tracing", (size_t) length) == 0)
1104
1178
            && (length >= 3)) {
1105
1179
        int wmTracing;
1106
 
        if ((objc != 2) && (objc != 3)) {
 
1180
        /* Perl/Tk: increased parameter position by one because of implicite window parameter */
 
1181
        if ((objc != 3) && (objc != 4)) {
1107
1182
            Tcl_WrongNumArgs(interp, 2, objv, "?boolean?");
1108
1183
            return TCL_ERROR;
1109
1184
        }
1110
 
        if (objc == 2) {
 
1185
        if (objc == 3) {
1111
1186
            Tcl_SetResult(interp,
1112
1187
                    ((dispPtr->flags & TK_DISPLAY_WM_TRACING) ? "1" : ""),
1113
1188
                    TCL_STATIC);
1114
1189
            return TCL_OK;
1115
1190
        }
1116
 
        if (Tcl_GetBooleanFromObj(interp, objv[2], &wmTracing) != TCL_OK) {
 
1191
        if (Tcl_GetBooleanFromObj(interp, objv[3], &wmTracing) != TCL_OK) {
1117
1192
            return TCL_ERROR;
1118
1193
        }
1119
1194
        if (wmTracing) {
1147
1222
    }
1148
1223
    else if ((enum options) index != WMOPT_RELEASE) {
1149
1224
        Tcl_AppendResult(interp, "window \"", winPtr->pathName,
1150
 
                "\" isn't a top-level window", (char *) NULL);
 
1225
                "\" isn't a top-level window", NULL);
1151
1226
            return TCL_ERROR;
1152
1227
    }
1153
1228
 
1154
1229
    switch ((enum options) index) {
1155
 
      case WMOPT_ASPECT:
 
1230
    case WMOPT_ASPECT:
1156
1231
        return WmAspectCmd(tkwin, winPtr, interp, objc, objv);
1157
 
      case WMOPT_ATTRIBUTES:
 
1232
    case WMOPT_ATTRIBUTES:
1158
1233
        return WmAttributesCmd(tkwin, winPtr, interp, objc, objv);
1159
 
      case WMOPT_CLIENT:
 
1234
    case WMOPT_CLIENT:
1160
1235
        return WmClientCmd(tkwin, winPtr, interp, objc, objv);
1161
 
      case WMOPT_CAPTURE:
 
1236
    case WMOPT_CAPTURE:
1162
1237
        return WmCaptureCmd(tkwin, winPtr, interp, objc, objv);
1163
 
      case WMOPT_COLORMAPWINDOWS:
 
1238
    case WMOPT_COLORMAPWINDOWS:
1164
1239
        return WmColormapwindowsCmd(tkwin, winPtr, interp, objc, objv);
1165
 
      case WMOPT_COMMAND:
 
1240
    case WMOPT_COMMAND:
1166
1241
        return WmCommandCmd(tkwin, winPtr, interp, objc, objv);
1167
 
      case WMOPT_DEICONIFY:
 
1242
    case WMOPT_DEICONIFY:
1168
1243
        return WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv);
1169
 
      case WMOPT_FOCUSMODEL:
 
1244
    case WMOPT_FOCUSMODEL:
1170
1245
        return WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv);
1171
 
      case WMOPT_FRAME:
 
1246
    case WMOPT_FRAME:
1172
1247
        return WmFrameCmd(tkwin, winPtr, interp, objc, objv);
1173
 
      case WMOPT_GEOMETRY:
 
1248
    case WMOPT_GEOMETRY:
1174
1249
        return WmGeometryCmd(tkwin, winPtr, interp, objc, objv);
1175
 
      case WMOPT_GRID:
 
1250
    case WMOPT_GRID:
1176
1251
        return WmGridCmd(tkwin, winPtr, interp, objc, objv);
1177
 
      case WMOPT_GROUP:
 
1252
    case WMOPT_GROUP:
1178
1253
        return WmGroupCmd(tkwin, winPtr, interp, objc, objv);
1179
 
      case WMOPT_ICONBITMAP:
 
1254
    case WMOPT_ICONBITMAP:
1180
1255
        return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv);
1181
 
      case WMOPT_ICONIFY:
 
1256
    case WMOPT_ICONIFY:
1182
1257
        return WmIconifyCmd(tkwin, winPtr, interp, objc, objv);
1183
 
      case WMOPT_ICONIMAGE:
 
1258
    case WMOPT_ICONIMAGE:
1184
1259
        return WmIconimageCmd(tkwin, winPtr, interp, objc, objv);
1185
 
      case WMOPT_ICONMASK:
 
1260
    case WMOPT_ICONMASK:
1186
1261
        return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv);
1187
 
      case WMOPT_ICONNAME:
 
1262
    case WMOPT_ICONNAME:
1188
1263
        return WmIconnameCmd(tkwin, winPtr, interp, objc, objv);
1189
 
      case WMOPT_ICONPOSITION:
 
1264
    case WMOPT_ICONPHOTO:
 
1265
        return WmIconphotoCmd(tkwin, winPtr, interp, objc, objv);
 
1266
    case WMOPT_ICONPOSITION:
1190
1267
        return WmIconpositionCmd(tkwin, winPtr, interp, objc, objv);
1191
 
      case WMOPT_ICONWINDOW:
 
1268
    case WMOPT_ICONWINDOW:
1192
1269
        return WmIconwindowCmd(tkwin, winPtr, interp, objc, objv);
1193
 
      case WMOPT_MAXSIZE:
 
1270
    case WMOPT_MAXSIZE:
1194
1271
        return WmMaxsizeCmd(tkwin, winPtr, interp, objc, objv);
1195
 
      case WMOPT_MINSIZE:
 
1272
    case WMOPT_MINSIZE:
1196
1273
        return WmMinsizeCmd(tkwin, winPtr, interp, objc, objv);
1197
 
      case WMOPT_OVERRIDEREDIRECT:
 
1274
    case WMOPT_OVERRIDEREDIRECT:
1198
1275
        return WmOverrideredirectCmd(tkwin, winPtr, interp, objc, objv);
1199
 
      case WMOPT_POSITIONFROM:
 
1276
    case WMOPT_POSITIONFROM:
1200
1277
        return WmPositionfromCmd(tkwin, winPtr, interp, objc, objv);
1201
 
      case WMOPT_PROTOCOL:
 
1278
    case WMOPT_PROTOCOL:
1202
1279
        return WmProtocolCmd(tkwin, winPtr, interp, objc, objv);
1203
 
      case WMOPT_RESIZABLE:
 
1280
    case WMOPT_RESIZABLE:
1204
1281
        return WmResizableCmd(tkwin, winPtr, interp, objc, objv);
1205
 
      case WMOPT_RELEASE:
 
1282
    case WMOPT_RELEASE:
1206
1283
        return WmReleaseCmd(tkwin, winPtr, interp, objc, objv);
1207
 
      case WMOPT_SIZEFROM:
 
1284
    case WMOPT_SIZEFROM:
1208
1285
        return WmSizefromCmd(tkwin, winPtr, interp, objc, objv);
1209
 
      case WMOPT_STACKORDER:
 
1286
    case WMOPT_STACKORDER:
1210
1287
        return WmStackorderCmd(tkwin, winPtr, interp, objc, objv);
1211
 
      case WMOPT_STATE:
 
1288
    case WMOPT_STATE:
1212
1289
        return WmStateCmd(tkwin, winPtr, interp, objc, objv);
1213
 
      case WMOPT_TITLE:
 
1290
    case WMOPT_TITLE:
1214
1291
        return WmTitleCmd(tkwin, winPtr, interp, objc, objv);
1215
 
      case WMOPT_TRANSIENT:
 
1292
    case WMOPT_TRANSIENT:
1216
1293
        return WmTransientCmd(tkwin, winPtr, interp, objc, objv);
1217
 
      case WMOPT_WITHDRAW:
 
1294
    case WMOPT_WITHDRAW:
1218
1295
        return WmWithdrawCmd(tkwin, winPtr, interp, objc, objv);
1219
 
      case WMOPT_WRAPPER:
 
1296
    case WMOPT_WRAPPER:
1220
1297
        return WmWrapperCmd(tkwin, winPtr, interp, objc, objv);
1221
1298
    }
1222
1299
 
1229
1306
 *
1230
1307
 * WmAspectCmd --
1231
1308
 *
1232
 
 *      This procedure is invoked to process the "wm aspect" Tcl command.
1233
 
 *      See the user documentation for details on what it does.
 
1309
 *      This function is invoked to process the "wm aspect" Tcl command. See
 
1310
 *      the user documentation for details on what it does.
1234
1311
 *
1235
1312
 * Results:
1236
1313
 *      A standard Tcl result.
1242
1319
 */
1243
1320
 
1244
1321
static int
1245
 
WmAspectCmd(tkwin, winPtr, interp, objc, objv)
1246
 
    Tk_Window tkwin;            /* Main window of the application. */
1247
 
    TkWindow *winPtr;           /* Toplevel to work with */
1248
 
    Tcl_Interp *interp;         /* Current interpreter. */
1249
 
    int objc;                   /* Number of arguments. */
1250
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1322
WmAspectCmd(
 
1323
    Tk_Window tkwin,            /* Main window of the application. */
 
1324
    TkWindow *winPtr,           /* Toplevel to work with */
 
1325
    Tcl_Interp *interp,         /* Current interpreter. */
 
1326
    int objc,                   /* Number of arguments. */
 
1327
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1251
1328
{
1252
1329
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1253
1330
    int numer1, denom1, numer2, denom2;
1259
1336
    }
1260
1337
    if (objc == 3) {
1261
1338
        if (wmPtr->sizeHintsFlags & PAspect) {
1262
 
            char buf[TCL_INTEGER_SPACE * 4];
1263
 
 
1264
 
            sprintf(buf, "%d %d %d %d", wmPtr->minAspect.x,
1265
 
                    wmPtr->minAspect.y, wmPtr->maxAspect.x,
1266
 
                    wmPtr->maxAspect.y);
1267
 
            Tcl_SetResult(interp, buf, TCL_VOLATILE);
 
1339
            Tcl_IntResults(interp, 4, 0, wmPtr->minAspect.x,
 
1340
                           wmPtr->minAspect.y, wmPtr->maxAspect.x,
 
1341
                           wmPtr->maxAspect.y);
1268
1342
        }
1269
1343
        return TCL_OK;
1270
1344
    }
1297
1371
/*
1298
1372
 *----------------------------------------------------------------------
1299
1373
 *
 
1374
 * WmSetAttribute --
 
1375
 *
 
1376
 *      Helper routine for WmAttributesCmd.  Sets the value
 
1377
 *      of the specified attribute.
 
1378
 *
 
1379
 * Returns:
 
1380
 *
 
1381
 *      TCL_OK if successful, TCL_ERROR otherwise.  In case of an
 
1382
 *      error, leaves a message in the interpreter's result.
 
1383
 *
 
1384
 *----------------------------------------------------------------------
 
1385
 */
 
1386
static int WmSetAttribute(
 
1387
    TkWindow *winPtr,           /* Toplevel to work with */
 
1388
    Tcl_Interp *interp,         /* Current interpreter */
 
1389
    WmAttribute attribute,      /* Code of attribute to set */
 
1390
    Tcl_Obj *value)             /* New value */
 
1391
{
 
1392
    WmInfo *wmPtr = winPtr->wmInfoPtr;
 
1393
    switch (attribute) {
 
1394
        case WMATT_ALPHA:
 
1395
        {
 
1396
            unsigned long opacity;      /* 0=transparent, 0xFFFFFFFF=opaque */
 
1397
 
 
1398
            if (TCL_OK != Tcl_GetDoubleFromObj(
 
1399
                    interp, value, &wmPtr->reqState.alpha)) {
 
1400
                return TCL_ERROR;
 
1401
            }
 
1402
            if (wmPtr->reqState.alpha < 0.0) {
 
1403
                wmPtr->reqState.alpha = 0.0;
 
1404
            }
 
1405
            if (wmPtr->reqState.alpha > 1.0) {
 
1406
                wmPtr->reqState.alpha = 1.0;
 
1407
            }
 
1408
 
 
1409
            if (!wmPtr->wrapperPtr) {
 
1410
                break;
 
1411
            }
 
1412
 
 
1413
            opacity = 0xFFFFFFFFul * wmPtr->reqState.alpha;
 
1414
            XChangeProperty(winPtr->display, wmPtr->wrapperPtr->window, 
 
1415
                    Tk_InternAtom((Tk_Window)winPtr, "_NET_WM_WINDOW_OPACITY"),
 
1416
                    XA_CARDINAL, 32, PropModeReplace,
 
1417
                    (unsigned char *)&opacity, 1L);
 
1418
            wmPtr->attributes.alpha = wmPtr->reqState.alpha;
 
1419
 
 
1420
            break;
 
1421
        }
 
1422
        case WMATT_TOPMOST:
 
1423
            if (TCL_OK != Tcl_GetBooleanFromObj(
 
1424
                    interp, value, &wmPtr->reqState.topmost)) {
 
1425
                return TCL_ERROR;
 
1426
            }
 
1427
            SetNetWmState(winPtr, 
 
1428
                "_NET_WM_STATE_ABOVE", wmPtr->reqState.topmost);
 
1429
            break;
 
1430
        case WMATT_ZOOMED:
 
1431
            if (TCL_OK != Tcl_GetBooleanFromObj(
 
1432
                    interp, value, &wmPtr->reqState.zoomed)) {
 
1433
                return TCL_ERROR;
 
1434
            }
 
1435
            SetNetWmState(winPtr,
 
1436
                "_NET_WM_STATE_MAXIMIZED_VERT", wmPtr->reqState.zoomed);
 
1437
            SetNetWmState(winPtr,
 
1438
                "_NET_WM_STATE_MAXIMIZED_HORZ", wmPtr->reqState.zoomed);
 
1439
            break;
 
1440
        case WMATT_FULLSCREEN:
 
1441
            if (TCL_OK != Tcl_GetBooleanFromObj(
 
1442
                    interp, value, &wmPtr->reqState.fullscreen)) {
 
1443
                return TCL_ERROR;
 
1444
            }
 
1445
            SetNetWmState(winPtr,
 
1446
                "_NET_WM_STATE_FULLSCREEN", wmPtr->reqState.fullscreen);
 
1447
            break;
 
1448
        case _WMATT_LAST_ATTRIBUTE:     /* NOTREACHED */
 
1449
            return TCL_ERROR;
 
1450
    }
 
1451
    return TCL_OK;
 
1452
}
 
1453
 
 
1454
/*
 
1455
 *----------------------------------------------------------------------
 
1456
 *
 
1457
 * WmGetAttribute --
 
1458
 *
 
1459
 *      Helper routine for WmAttributesCmd.  Returns the current value
 
1460
 *      of the specified attribute.
 
1461
 *
 
1462
 * See also: CheckNetWmState().
 
1463
 *
 
1464
 *----------------------------------------------------------------------
 
1465
 */
 
1466
static Tcl_Obj *WmGetAttribute(
 
1467
    TkWindow *winPtr,           /* Toplevel to work with */
 
1468
    WmAttribute attribute)      /* Code of attribute to get */
 
1469
{
 
1470
    WmInfo *wmPtr = winPtr->wmInfoPtr;
 
1471
    switch (attribute) {
 
1472
        case WMATT_ALPHA:
 
1473
            return Tcl_NewDoubleObj(wmPtr->attributes.alpha);
 
1474
        case WMATT_TOPMOST:
 
1475
            return Tcl_NewBooleanObj(wmPtr->attributes.topmost);
 
1476
        case WMATT_ZOOMED:
 
1477
            return Tcl_NewBooleanObj(wmPtr->attributes.zoomed);
 
1478
        case WMATT_FULLSCREEN:
 
1479
            return Tcl_NewBooleanObj(wmPtr->attributes.fullscreen);
 
1480
        case _WMATT_LAST_ATTRIBUTE:     /*NOTREACHED*/
 
1481
            break;
 
1482
    }
 
1483
    /*NOTREACHED*/
 
1484
    return NULL;
 
1485
}
 
1486
 
 
1487
/*
 
1488
 *----------------------------------------------------------------------
 
1489
 *
1300
1490
 * WmAttributesCmd --
1301
1491
 *
1302
 
 *      This procedure is invoked to process the "wm attributes" Tcl command.
1303
 
 *      See the user documentation for details on what it does.
1304
 
 *
1305
 
 * Results:
1306
 
 *      A standard Tcl result.
1307
 
 *
1308
 
 * Side effects:
1309
 
 *      See the user documentation.
 
1492
 *      This function is invoked to process the "wm attributes" Tcl command.
 
1493
 *
 
1494
 * Syntax:
 
1495
 *
 
1496
 *      wm attributes $win ?-attribute ?value attribute value...??
 
1497
 *
 
1498
 * Notes:
 
1499
 *
 
1500
 *      Attributes of mapped windows are set by sending a _NET_WM_STATE
 
1501
 *      ClientMessage to the root window (see SetNetWmState).
 
1502
 *      For withdrawn windows, we keep track of the requested attribute
 
1503
 *      state, and set the _NET_WM_STATE property ourselves immediately
 
1504
 *      prior to mapping the window.
 
1505
 *
 
1506
 * See also: TIP#231, EWMH.
1310
1507
 *
1311
1508
 *----------------------------------------------------------------------
1312
1509
 */
1313
1510
 
1314
1511
static int
1315
 
WmAttributesCmd(tkwin, winPtr, interp, objc, objv)
1316
 
    Tk_Window tkwin;            /* Main window of the application. */
1317
 
    TkWindow *winPtr;           /* Toplevel to work with */
1318
 
    Tcl_Interp *interp;         /* Current interpreter. */
1319
 
    int objc;                   /* Number of arguments. */
1320
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1512
WmAttributesCmd(
 
1513
    Tk_Window tkwin,            /* Main window of the application. */
 
1514
    TkWindow *winPtr,           /* Toplevel to work with */
 
1515
    Tcl_Interp *interp,         /* Current interpreter. */
 
1516
    int objc,                   /* Number of arguments. */
 
1517
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1321
1518
{
1322
 
    if (objc != 3) {
1323
 
        Tcl_WrongNumArgs(interp, 2, objv, "window");
 
1519
    int attribute = 0;
 
1520
    if (objc == 3) {            /* wm attributes $win */
 
1521
        Tcl_Obj *result = Tcl_NewListObj(0,0);
 
1522
        for (attribute = 0; attribute < _WMATT_LAST_ATTRIBUTE; ++attribute) {
 
1523
            Tcl_ListObjAppendElement(interp, result,
 
1524
                    Tcl_NewStringObj(WmAttributeNames[attribute], -1));
 
1525
            Tcl_ListObjAppendElement(interp, result,
 
1526
                    WmGetAttribute(winPtr, attribute));
 
1527
        }
 
1528
        Tcl_SetObjResult(interp, result);
 
1529
        return TCL_OK;
 
1530
    } else if (objc == 4)  {    /* wm attributes $win -attribute */
 
1531
        if (Tcl_GetIndexFromObj(interp, objv[3], WmAttributeNames,
 
1532
                    "attribute", 0, &attribute) != TCL_OK) {
 
1533
            return TCL_ERROR;
 
1534
        }
 
1535
        Tcl_SetObjResult(interp, 
 
1536
                WmGetAttribute(winPtr, attribute));
 
1537
        return TCL_OK;
 
1538
    } else if ((objc - 3) % 2 == 0) {   /* wm attributes $win -att value... */
 
1539
        int i;
 
1540
        for (i = 3; i < objc; i += 2) {
 
1541
            if (Tcl_GetIndexFromObj(interp, objv[i], WmAttributeNames,
 
1542
                        "attribute", 0, &attribute) != TCL_OK) {
 
1543
                return TCL_ERROR;
 
1544
            }
 
1545
            if (WmSetAttribute(winPtr,interp,attribute,objv[i+1]) != TCL_OK) {
 
1546
                return TCL_ERROR;
 
1547
            }
 
1548
        }
 
1549
        return TCL_OK;
 
1550
    } else {
 
1551
        Tcl_WrongNumArgs(interp, 2, objv, "window ?-attribute ?value ...??");
1324
1552
        return TCL_ERROR;
1325
1553
    }
1326
1554
    return TCL_OK;
1331
1559
 *
1332
1560
 * WmClientCmd --
1333
1561
 *
1334
 
 *      This procedure is invoked to process the "wm client" Tcl command.
1335
 
 *      See the user documentation for details on what it does.
 
1562
 *      This function is invoked to process the "wm client" Tcl command. See
 
1563
 *      the user documentation for details on what it does.
1336
1564
 *
1337
1565
 * Results:
1338
1566
 *      A standard Tcl result.
1344
1572
 */
1345
1573
 
1346
1574
static int
1347
 
WmClientCmd(tkwin, winPtr, interp, objc, objv)
1348
 
    Tk_Window tkwin;            /* Main window of the application. */
1349
 
    TkWindow *winPtr;           /* Toplevel to work with */
1350
 
    Tcl_Interp *interp;         /* Current interpreter. */
1351
 
    int objc;                   /* Number of arguments. */
1352
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1575
WmClientCmd(
 
1576
    Tk_Window tkwin,            /* Main window of the application. */
 
1577
    TkWindow *winPtr,           /* Toplevel to work with */
 
1578
    Tcl_Interp *interp,         /* Current interpreter. */
 
1579
    int objc,                   /* Number of arguments. */
 
1580
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1353
1581
{
1354
1582
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1355
1583
    char *argv3;
1372
1600
            wmPtr->clientMachine = NULL;
1373
1601
            if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
1374
1602
                XDeleteProperty(winPtr->display, wmPtr->wrapperPtr->window,
1375
 
                        Tk_InternAtom((Tk_Window) winPtr,
1376
 
                                "WM_CLIENT_MACHINE"));
 
1603
                        Tk_InternAtom((Tk_Window)winPtr, "WM_CLIENT_MACHINE"));
1377
1604
            }
1378
1605
        }
1379
1606
        return TCL_OK;
1407
1634
 *
1408
1635
 * WmColormapwindowsCmd --
1409
1636
 *
1410
 
 *      This procedure is invoked to process the "wm colormapwindows"
1411
 
 *      Tcl command.
1412
 
 *      See the user documentation for details on what it does.
 
1637
 *      This function is invoked to process the "wm colormapwindows" Tcl
 
1638
 *      command. See the user documentation for details on what it does.
1413
1639
 *
1414
1640
 * Results:
1415
1641
 *      A standard Tcl result.
1421
1647
 */
1422
1648
 
1423
1649
static int
1424
 
WmColormapwindowsCmd(tkwin, winPtr, interp, objc, objv)
1425
 
    Tk_Window tkwin;            /* Main window of the application. */
1426
 
    TkWindow *winPtr;           /* Toplevel to work with */
1427
 
    Tcl_Interp *interp;         /* Current interpreter. */
1428
 
    int objc;                   /* Number of arguments. */
1429
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1650
WmColormapwindowsCmd(
 
1651
    Tk_Window tkwin,            /* Main window of the application. */
 
1652
    TkWindow *winPtr,           /* Toplevel to work with */
 
1653
    Tcl_Interp *interp,         /* Current interpreter. */
 
1654
    int objc,                   /* Number of arguments. */
 
1655
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1430
1656
{
1431
1657
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1432
1658
    Window *cmapList;
1453
1679
                    && (wmPtr->flags & WM_ADDED_TOPLEVEL_COLORMAP)) {
1454
1680
                break;
1455
1681
            }
1456
 
            winPtr2  = (TkWindow *) Tk_IdToWindow(winPtr->display,
 
1682
            winPtr2 = (TkWindow *) Tk_IdToWindow(winPtr->display,
1457
1683
                    cmapList[i]);
1458
1684
            if (winPtr2 == NULL) {
1459
1685
                sprintf(buffer, "0x%lx", cmapList[i]);
1474
1700
    gotToplevel = 0;
1475
1701
    for (i = 0; i < windowObjc; i++) {
1476
1702
        if (TkGetWindowFromObj(interp, tkwin, windowObjv[i],
1477
 
                (Tk_Window *) &winPtr2) != TCL_OK)
1478
 
        {
 
1703
                (Tk_Window *) &winPtr2) != TCL_OK) {
1479
1704
            ckfree((char *) cmapList);
1480
1705
            return TCL_ERROR;
1481
1706
        }
1506
1731
 *
1507
1732
 * WmCommandCmd --
1508
1733
 *
1509
 
 *      This procedure is invoked to process the "wm command" Tcl command.
1510
 
 *      See the user documentation for details on what it does.
 
1734
 *      This function is invoked to process the "wm command" Tcl command. See
 
1735
 *      the user documentation for details on what it does.
1511
1736
 *
1512
1737
 * Results:
1513
1738
 *      A standard Tcl result.
1519
1744
 */
1520
1745
 
1521
1746
static int
1522
 
WmCommandCmd(tkwin, winPtr, interp, objc, objv)
1523
 
    Tk_Window tkwin;            /* Main window of the application. */
1524
 
    TkWindow *winPtr;           /* Toplevel to work with */
1525
 
    Tcl_Interp *interp;         /* Current interpreter. */
1526
 
    int objc;                   /* Number of arguments. */
1527
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1747
WmCommandCmd(
 
1748
    Tk_Window tkwin,            /* Main window of the application. */
 
1749
    TkWindow *winPtr,           /* Toplevel to work with */
 
1750
    Tcl_Interp *interp,         /* Current interpreter. */
 
1751
    int objc,                   /* Number of arguments. */
 
1752
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1528
1753
{
1529
1754
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1530
1755
    char *argv3;
1600
1825
 *
1601
1826
 * WmDeiconifyCmd --
1602
1827
 *
1603
 
 *      This procedure is invoked to process the "wm deiconify" Tcl command.
 
1828
 *      This function is invoked to process the "wm deiconify" Tcl command.
1604
1829
 *      See the user documentation for details on what it does.
1605
1830
 *
1606
1831
 * Results:
1613
1838
 */
1614
1839
 
1615
1840
static int
1616
 
WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv)
1617
 
    Tk_Window tkwin;            /* Main window of the application. */
1618
 
    TkWindow *winPtr;           /* Toplevel to work with */
1619
 
    Tcl_Interp *interp;         /* Current interpreter. */
1620
 
    int objc;                   /* Number of arguments. */
1621
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1841
WmDeiconifyCmd(
 
1842
    Tk_Window tkwin,            /* Main window of the application. */
 
1843
    TkWindow *winPtr,           /* Toplevel to work with */
 
1844
    Tcl_Interp *interp,         /* Current interpreter. */
 
1845
    int objc,                   /* Number of arguments. */
 
1846
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1622
1847
{
1623
1848
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1624
1849
 
1628
1853
    }
1629
1854
    if (wmPtr->iconFor != NULL) {
1630
1855
        Tcl_AppendResult(interp, "can't deiconify ", Tcl_GetString(objv[2]),
1631
 
                ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
1632
 
                (char *) NULL);
 
1856
                ": it is an icon for ", Tk_PathName(wmPtr->iconFor), NULL);
1633
1857
        return TCL_ERROR;
1634
1858
    }
1635
1859
    if (winPtr->flags & TK_EMBEDDED) {
1636
1860
        Tcl_AppendResult(interp, "can't deiconify ", winPtr->pathName,
1637
 
                ": it is an embedded window", (char *) NULL);
 
1861
                ": it is an embedded window", NULL);
1638
1862
        return TCL_ERROR;
1639
1863
    }
1640
1864
    wmPtr->flags &= ~WM_WITHDRAWN;
1647
1871
 *
1648
1872
 * WmFocusmodelCmd --
1649
1873
 *
1650
 
 *      This procedure is invoked to process the "wm focusmodel" Tcl command.
 
1874
 *      This function is invoked to process the "wm focusmodel" Tcl command.
1651
1875
 *      See the user documentation for details on what it does.
1652
1876
 *
1653
1877
 * Results:
1660
1884
 */
1661
1885
 
1662
1886
static int
1663
 
WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv)
1664
 
    Tk_Window tkwin;            /* Main window of the application. */
1665
 
    TkWindow *winPtr;           /* Toplevel to work with */
1666
 
    Tcl_Interp *interp;         /* Current interpreter. */
1667
 
    int objc;                   /* Number of arguments. */
1668
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1887
WmFocusmodelCmd(
 
1888
    Tk_Window tkwin,            /* Main window of the application. */
 
1889
    TkWindow *winPtr,           /* Toplevel to work with */
 
1890
    Tcl_Interp *interp,         /* Current interpreter. */
 
1891
    int objc,                   /* Number of arguments. */
 
1892
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1669
1893
{
1670
1894
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1671
1895
    static CONST char *optionStrings[] = {
1672
 
        "active", "passive", (char *) NULL };
 
1896
        "active", "passive", NULL };
1673
1897
    enum options {
1674
1898
        OPT_ACTIVE, OPT_PASSIVE };
1675
1899
    int index;
1702
1926
 *
1703
1927
 * WmFrameCmd --
1704
1928
 *
1705
 
 *      This procedure is invoked to process the "wm frame" Tcl command.
1706
 
 *      See the user documentation for details on what it does.
 
1929
 *      This function is invoked to process the "wm frame" Tcl command. See
 
1930
 *      the user documentation for details on what it does.
1707
1931
 *
1708
1932
 * Results:
1709
1933
 *      A standard Tcl result.
1715
1939
 */
1716
1940
 
1717
1941
static int
1718
 
WmFrameCmd(tkwin, winPtr, interp, objc, objv)
1719
 
    Tk_Window tkwin;            /* Main window of the application. */
1720
 
    TkWindow *winPtr;           /* Toplevel to work with */
1721
 
    Tcl_Interp *interp;         /* Current interpreter. */
1722
 
    int objc;                   /* Number of arguments. */
1723
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1942
WmFrameCmd(
 
1943
    Tk_Window tkwin,            /* Main window of the application. */
 
1944
    TkWindow *winPtr,           /* Toplevel to work with */
 
1945
    Tcl_Interp *interp,         /* Current interpreter. */
 
1946
    int objc,                   /* Number of arguments. */
 
1947
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1724
1948
{
1725
1949
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1726
1950
    Window window;
1744
1968
 *
1745
1969
 * WmGeometryCmd --
1746
1970
 *
1747
 
 *      This procedure is invoked to process the "wm geometry" Tcl command.
 
1971
 *      This function is invoked to process the "wm geometry" Tcl command.
1748
1972
 *      See the user documentation for details on what it does.
1749
1973
 *
1750
1974
 * Results:
1757
1981
 */
1758
1982
 
1759
1983
static int
1760
 
WmGeometryCmd(tkwin, winPtr, interp, objc, objv)
1761
 
    Tk_Window tkwin;            /* Main window of the application. */
1762
 
    TkWindow *winPtr;           /* Toplevel to work with */
1763
 
    Tcl_Interp *interp;         /* Current interpreter. */
1764
 
    int objc;                   /* Number of arguments. */
1765
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
1984
WmGeometryCmd(
 
1985
    Tk_Window tkwin,            /* Main window of the application. */
 
1986
    TkWindow *winPtr,           /* Toplevel to work with */
 
1987
    Tcl_Interp *interp,         /* Current interpreter. */
 
1988
    int objc,                   /* Number of arguments. */
 
1989
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1766
1990
{
1767
1991
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1768
1992
    char xSign, ySign;
1807
2031
 *
1808
2032
 * WmGridCmd --
1809
2033
 *
1810
 
 *      This procedure is invoked to process the "wm grid" Tcl command.
1811
 
 *      See the user documentation for details on what it does.
 
2034
 *      This function is invoked to process the "wm grid" Tcl command. See the
 
2035
 *      user documentation for details on what it does.
1812
2036
 *
1813
2037
 * Results:
1814
2038
 *      A standard Tcl result.
1820
2044
 */
1821
2045
 
1822
2046
static int
1823
 
WmGridCmd(tkwin, winPtr, interp, objc, objv)
1824
 
    Tk_Window tkwin;            /* Main window of the application. */
1825
 
    TkWindow *winPtr;           /* Toplevel to work with */
1826
 
    Tcl_Interp *interp;         /* Current interpreter. */
1827
 
    int objc;                   /* Number of arguments. */
1828
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2047
WmGridCmd(
 
2048
    Tk_Window tkwin,            /* Main window of the application. */
 
2049
    TkWindow *winPtr,           /* Toplevel to work with */
 
2050
    Tcl_Interp *interp,         /* Current interpreter. */
 
2051
    int objc,                   /* Number of arguments. */
 
2052
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1829
2053
{
1830
2054
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1831
2055
    int reqWidth, reqHeight, widthInc, heightInc;
1837
2061
    }
1838
2062
    if (objc == 3) {
1839
2063
        if (wmPtr->sizeHintsFlags & PBaseSize) {
1840
 
            char buf[TCL_INTEGER_SPACE * 4];
1841
 
 
1842
 
            sprintf(buf, "%d %d %d %d", wmPtr->reqGridWidth,
1843
 
                    wmPtr->reqGridHeight, wmPtr->widthInc,
1844
 
                    wmPtr->heightInc);
1845
 
            Tcl_SetResult(interp, buf, TCL_VOLATILE);
 
2064
            Tcl_IntResults(interp, 4, 0, wmPtr->reqGridWidth,
 
2065
                           wmPtr->reqGridHeight, wmPtr->widthInc,
 
2066
                           wmPtr->heightInc);
1846
2067
        }
1847
2068
        return TCL_OK;
1848
2069
    }
1849
2070
    if (*Tcl_GetString(objv[3]) == '\0') {
1850
2071
        /*
1851
 
         * Turn off gridding and reset the width and height
1852
 
         * to make sense as ungridded numbers.
 
2072
         * Turn off gridding and reset the width and height to make sense as
 
2073
         * ungridded numbers.
1853
2074
         */
1854
2075
 
1855
2076
        wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
1865
2086
        if ((Tcl_GetIntFromObj(interp, objv[3], &reqWidth) != TCL_OK)
1866
2087
                || (Tcl_GetIntFromObj(interp, objv[4], &reqHeight) != TCL_OK)
1867
2088
                || (Tcl_GetIntFromObj(interp, objv[5], &widthInc) != TCL_OK)
1868
 
                || (Tcl_GetIntFromObj(interp, objv[6], &heightInc) != TCL_OK)) {
 
2089
                || (Tcl_GetIntFromObj(interp, objv[6], &heightInc) !=TCL_OK)) {
1869
2090
            return TCL_ERROR;
1870
2091
        }
1871
2092
        if (reqWidth < 0) {
1876
2097
            Tcl_SetResult(interp, "baseHeight can't be < 0", TCL_STATIC);
1877
2098
            return TCL_ERROR;
1878
2099
        }
1879
 
        if (widthInc < 0) {
1880
 
            Tcl_SetResult(interp, "widthInc can't be < 0", TCL_STATIC);
 
2100
        if (widthInc <= 0) {
 
2101
            Tcl_SetResult(interp, "widthInc can't be <= 0", TCL_STATIC);
1881
2102
            return TCL_ERROR;
1882
2103
        }
1883
 
        if (heightInc < 0) {
1884
 
            Tcl_SetResult(interp, "heightInc can't be < 0", TCL_STATIC);
 
2104
        if (heightInc <= 0) {
 
2105
            Tcl_SetResult(interp, "heightInc can't be <= 0", TCL_STATIC);
1885
2106
            return TCL_ERROR;
1886
2107
        }
1887
2108
        Tk_SetGrid((Tk_Window) winPtr, reqWidth, reqHeight, widthInc,
1897
2118
 *
1898
2119
 * WmGroupCmd --
1899
2120
 *
1900
 
 *      This procedure is invoked to process the "wm group" Tcl command.
1901
 
 *      See the user documentation for details on what it does.
 
2121
 *      This function is invoked to process the "wm group" Tcl command. See
 
2122
 *      the user documentation for details on what it does.
1902
2123
 *
1903
2124
 * Results:
1904
2125
 *      A standard Tcl result.
1910
2131
 */
1911
2132
 
1912
2133
static int
1913
 
WmGroupCmd(tkwin, winPtr, interp, objc, objv)
1914
 
    Tk_Window tkwin;            /* Main window of the application. */
1915
 
    TkWindow *winPtr;           /* Toplevel to work with */
1916
 
    Tcl_Interp *interp;         /* Current interpreter. */
1917
 
    int objc;                   /* Number of arguments. */
1918
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2134
WmGroupCmd(
 
2135
    Tk_Window tkwin,            /* Main window of the application. */
 
2136
    TkWindow *winPtr,           /* Toplevel to work with */
 
2137
    Tcl_Interp *interp,         /* Current interpreter. */
 
2138
    int objc,                   /* Number of arguments. */
 
2139
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1919
2140
{
1920
2141
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1921
2142
    Tk_Window tkwin2;
1973
2194
 *
1974
2195
 * WmIconbitmapCmd --
1975
2196
 *
1976
 
 *      This procedure is invoked to process the "wm iconbitmap" Tcl command.
 
2197
 *      This function is invoked to process the "wm iconbitmap" Tcl command.
1977
2198
 *      See the user documentation for details on what it does.
1978
2199
 *
1979
2200
 * Results:
1986
2207
 */
1987
2208
 
1988
2209
static int
1989
 
WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv)
1990
 
    Tk_Window tkwin;            /* Main window of the application. */
1991
 
    TkWindow *winPtr;           /* Toplevel to work with */
1992
 
    Tcl_Interp *interp;         /* Current interpreter. */
1993
 
    int objc;                   /* Number of arguments. */
1994
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2210
WmIconbitmapCmd(
 
2211
    Tk_Window tkwin,            /* Main window of the application. */
 
2212
    TkWindow *winPtr,           /* Toplevel to work with */
 
2213
    Tcl_Interp *interp,         /* Current interpreter. */
 
2214
    int objc,                   /* Number of arguments. */
 
2215
    Tcl_Obj *CONST objv[])      /* Argument objects. */
1995
2216
{
1996
2217
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
1997
2218
    Pixmap pixmap;
2033
2254
 *
2034
2255
 * WmIconifyCmd --
2035
2256
 *
2036
 
 *      This procedure is invoked to process the "wm iconify" Tcl command.
2037
 
 *      See the user documentation for details on what it does.
 
2257
 *      This function is invoked to process the "wm iconify" Tcl command. See
 
2258
 *      the user documentation for details on what it does.
2038
2259
 *
2039
2260
 * Results:
2040
2261
 *      A standard Tcl result.
2046
2267
 */
2047
2268
 
2048
2269
static int
2049
 
WmIconifyCmd(tkwin, winPtr, interp, objc, objv)
2050
 
    Tk_Window tkwin;            /* Main window of the application. */
2051
 
    TkWindow *winPtr;           /* Toplevel to work with */
2052
 
    Tcl_Interp *interp;         /* Current interpreter. */
2053
 
    int objc;                   /* Number of arguments. */
2054
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2270
WmIconifyCmd(
 
2271
    Tk_Window tkwin,            /* Main window of the application. */
 
2272
    TkWindow *winPtr,           /* Toplevel to work with */
 
2273
    Tcl_Interp *interp,         /* Current interpreter. */
 
2274
    int objc,                   /* Number of arguments. */
 
2275
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2055
2276
{
2056
2277
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2057
2278
    if (objc != 3) {
2060
2281
    }
2061
2282
    if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
2062
2283
        Tcl_AppendResult(interp, "can't iconify \"", winPtr->pathName,
2063
 
                "\": override-redirect flag is set", (char *) NULL);
 
2284
                "\": override-redirect flag is set", NULL);
2064
2285
        return TCL_ERROR;
2065
2286
    }
2066
2287
    if (wmPtr->masterPtr != NULL) {
2067
2288
        Tcl_AppendResult(interp, "can't iconify \"", winPtr->pathName,
2068
 
                "\": it is a transient", (char *) NULL);
 
2289
                "\": it is a transient", NULL);
2069
2290
        return TCL_ERROR;
2070
2291
    }
2071
2292
    if (wmPtr->iconFor != NULL) {
2072
2293
        Tcl_AppendResult(interp, "can't iconify ", winPtr->pathName,
2073
 
                ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
2074
 
                (char *) NULL);
 
2294
                ": it is an icon for ", Tk_PathName(wmPtr->iconFor), NULL);
2075
2295
        return TCL_ERROR;
2076
2296
    }
2077
2297
    if (winPtr->flags & TK_EMBEDDED) {
2078
2298
        Tcl_AppendResult(interp, "can't iconify ", winPtr->pathName,
2079
 
                ": it is an embedded window", (char *) NULL);
 
2299
                ": it is an embedded window", NULL);
2080
2300
        return TCL_ERROR;
2081
2301
    }
2082
2302
    if (TkpWmSetState(winPtr, IconicState) == 0) {
2093
2313
 *
2094
2314
 * WmIconmaskCmd --
2095
2315
 *
2096
 
 *      This procedure is invoked to process the "wm iconmask" Tcl command.
 
2316
 *      This function is invoked to process the "wm iconmask" Tcl command.
2097
2317
 *      See the user documentation for details on what it does.
2098
2318
 *
2099
2319
 * Results:
2106
2326
 */
2107
2327
 
2108
2328
static int
2109
 
WmIconmaskCmd(tkwin, winPtr, interp, objc, objv)
2110
 
    Tk_Window tkwin;            /* Main window of the application. */
2111
 
    TkWindow *winPtr;           /* Toplevel to work with */
2112
 
    Tcl_Interp *interp;         /* Current interpreter. */
2113
 
    int objc;                   /* Number of arguments. */
2114
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2329
WmIconmaskCmd(
 
2330
    Tk_Window tkwin,            /* Main window of the application. */
 
2331
    TkWindow *winPtr,           /* Toplevel to work with */
 
2332
    Tcl_Interp *interp,         /* Current interpreter. */
 
2333
    int objc,                   /* Number of arguments. */
 
2334
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2115
2335
{
2116
2336
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2117
2337
    Pixmap pixmap;
2152
2372
 *
2153
2373
 * WmIconnameCmd --
2154
2374
 *
2155
 
 *      This procedure is invoked to process the "wm iconname" Tcl command.
 
2375
 *      This function is invoked to process the "wm iconname" Tcl command.
2156
2376
 *      See the user documentation for details on what it does.
2157
2377
 *
2158
2378
 * Results:
2165
2385
 */
2166
2386
 
2167
2387
static int
2168
 
WmIconnameCmd(tkwin, winPtr, interp, objc, objv)
2169
 
    Tk_Window tkwin;            /* Main window of the application. */
2170
 
    TkWindow *winPtr;           /* Toplevel to work with */
2171
 
    Tcl_Interp *interp;         /* Current interpreter. */
2172
 
    int objc;                   /* Number of arguments. */
2173
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2388
WmIconnameCmd(
 
2389
    Tk_Window tkwin,            /* Main window of the application. */
 
2390
    TkWindow *winPtr,           /* Toplevel to work with */
 
2391
    Tcl_Interp *interp,         /* Current interpreter. */
 
2392
    int objc,                   /* Number of arguments. */
 
2393
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2174
2394
{
2175
2395
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2176
2396
    char *argv3;
2193
2413
        wmPtr->iconName = ckalloc((unsigned) (length + 1));
2194
2414
        strcpy(wmPtr->iconName, argv3);
2195
2415
        if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
2196
 
            Tcl_DString ds;
2197
 
 
2198
 
            Tcl_UtfToExternalDString(NULL, wmPtr->iconName, -1, &ds);
2199
 
            XSetIconName(winPtr->display, wmPtr->wrapperPtr->window,
2200
 
                    Tcl_DStringValue(&ds));
2201
 
            Tcl_DStringFree(&ds);
2202
 
        }
 
2416
            UpdateTitle(winPtr);
 
2417
        }
 
2418
    }
 
2419
    return TCL_OK;
 
2420
}
 
2421
 
 
2422
/*
 
2423
 *----------------------------------------------------------------------
 
2424
 *
 
2425
 * WmIconphotoCmd --
 
2426
 *
 
2427
 *      This function is invoked to process the "wm iconphoto" Tcl command.
 
2428
 *      See the user documentation for details on what it does.
 
2429
 *
 
2430
 * Results:
 
2431
 *      A standard Tcl result.
 
2432
 *
 
2433
 * Side effects:
 
2434
 *      See the user documentation.
 
2435
 *
 
2436
 *----------------------------------------------------------------------
 
2437
 */
 
2438
 
 
2439
static int
 
2440
WmIconphotoCmd(
 
2441
    Tk_Window tkwin,            /* Main window of the application. */
 
2442
    TkWindow *winPtr,           /* Toplevel to work with */
 
2443
    Tcl_Interp *interp,         /* Current interpreter. */
 
2444
    int objc,                   /* Number of arguments. */
 
2445
    Tcl_Obj *CONST objv[])      /* Argument objects. */
 
2446
{
 
2447
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
 
2448
    Tk_PhotoHandle photo;
 
2449
    Tk_PhotoImageBlock block;
 
2450
    int i, size = 0, width, height, index = 0, x, y, isDefault = 0;
 
2451
    long R, G, B, A;
 
2452
    long *iconPropertyData;
 
2453
    unsigned char *pixelByte;
 
2454
 
 
2455
    if (objc < 4) {
 
2456
        Tcl_WrongNumArgs(interp, 2, objv,
 
2457
                "window ?-default? image1 ?image2 ...?");
 
2458
        return TCL_ERROR;
 
2459
    }
 
2460
    if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) {
 
2461
        isDefault = 1;
 
2462
        if (objc == 4) {
 
2463
            Tcl_WrongNumArgs(interp, 2, objv,
 
2464
                    "window ?-default? image1 ?image2 ...?");
 
2465
            return TCL_ERROR;
 
2466
        }
 
2467
    }
 
2468
 
 
2469
    /*
 
2470
     * Iterate over all images to retrieve their sizes, in order to allocate a
 
2471
     * buffer large enough to hold all images.
 
2472
     */
 
2473
 
 
2474
    for (i = 3 + isDefault; i < objc; i++) {
 
2475
        photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i]));
 
2476
        if (photo == NULL) {
 
2477
            Tcl_AppendResult(interp, "can't use \"", Tcl_GetString(objv[i]),
 
2478
                    "\" as iconphoto: not a photo image", NULL);
 
2479
            return TCL_ERROR;
 
2480
        }
 
2481
        Tk_PhotoGetSize(photo, &width, &height);
 
2482
 
 
2483
        /*
 
2484
         * We need to cardinals for width & height and one cardinal for each
 
2485
         * image pixel.
 
2486
         */
 
2487
 
 
2488
        size += 2 + width * height;
 
2489
    }
 
2490
 
 
2491
    /*
 
2492
     * We have calculated the size of the data. Try to allocate the needed
 
2493
     * memory space.
 
2494
     */
 
2495
 
 
2496
#ifdef NOTYET_XXX
 
2497
    iconPropertyData = (long *) Tcl_AttemptAlloc(sizeof(long)*size);
 
2498
#else
 
2499
    iconPropertyData = (long *) ckalloc(sizeof(long)*size);
 
2500
#endif
 
2501
    if (iconPropertyData == NULL) {
 
2502
        return TCL_ERROR;
 
2503
    }
 
2504
    memset(iconPropertyData, 0, sizeof(long)*size);
 
2505
 
 
2506
    for (i = 3 + isDefault; i < objc; i++) {
 
2507
        photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i]));
 
2508
        if (photo == NULL) {
 
2509
            Tcl_Free((char *) iconPropertyData);
 
2510
            return TCL_ERROR;
 
2511
        }
 
2512
        Tk_PhotoGetSize(photo, &width, &height);
 
2513
        Tk_PhotoGetImage(photo, &block);
 
2514
 
 
2515
        /*
 
2516
         * Each image data will be placed as an array of 32bit packed
 
2517
         * CARDINAL, in a window property named "_NET_WM_ICON": _NET_WM_ICON
 
2518
         *
 
2519
         * _NET_WM_ICON CARDINAL[][2+n]/32
 
2520
         *
 
2521
         * This is an array of possible icons for the client. This spec. does
 
2522
         * not stipulate what size these icons should be, but individual
 
2523
         * desktop environments or toolkits may do so. The Window Manager MAY
 
2524
         * scale any of these icons to an appropriate size.
 
2525
         *
 
2526
         * This is an array of 32bit packed CARDINAL ARGB with high byte being
 
2527
         * A, low byte being B. The first two cardinals are width, height.
 
2528
         * Data is in rows, left to right and top to bottom.
 
2529
         */
 
2530
 
 
2531
        /*
 
2532
         * Encode the image data in the iconPropertyData array.
 
2533
         */
 
2534
 
 
2535
        iconPropertyData[index++] = width;
 
2536
        iconPropertyData[index++] = height;
 
2537
        for (y = 0; y < height; y++) {
 
2538
            for (x = 0; x < width; x++) {
 
2539
                R = *(block.pixelPtr + x*block.pixelSize +
 
2540
                        y*block.pitch + block.offset[0]);
 
2541
                G = *(block.pixelPtr + x*block.pixelSize +
 
2542
                        y*block.pitch + block.offset[1]);
 
2543
                B = *(block.pixelPtr + x*block.pixelSize +
 
2544
                        y*block.pitch + block.offset[2]);
 
2545
                A = *(block.pixelPtr + x*block.pixelSize +
 
2546
                        y*block.pitch + block.offset[3]);
 
2547
                pixelByte = (unsigned char *) &iconPropertyData[index];
 
2548
                pixelByte[3] = A;
 
2549
                pixelByte[2] = R;
 
2550
                pixelByte[1] = G;
 
2551
                pixelByte[0] = B;
 
2552
                index++;
 
2553
            }
 
2554
        }
 
2555
    }
 
2556
    if (wmPtr->iconDataPtr != NULL) {
 
2557
        ckfree((char *)wmPtr->iconDataPtr);
 
2558
        wmPtr->iconDataPtr = NULL;
 
2559
    }
 
2560
    if (isDefault) {
 
2561
        if (winPtr->dispPtr->iconDataPtr != NULL) {
 
2562
            ckfree((char *) winPtr->dispPtr->iconDataPtr);
 
2563
        }
 
2564
        winPtr->dispPtr->iconDataPtr = (unsigned char *) iconPropertyData;
 
2565
        winPtr->dispPtr->iconDataSize = size;
 
2566
    } else {
 
2567
        wmPtr->iconDataPtr = (unsigned char *) iconPropertyData;
 
2568
        wmPtr->iconDataSize = size;
 
2569
    }
 
2570
    if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
 
2571
        UpdatePhotoIcon(winPtr);
2203
2572
    }
2204
2573
    return TCL_OK;
2205
2574
}
2209
2578
 *
2210
2579
 * WmIconpositionCmd --
2211
2580
 *
2212
 
 *      This procedure is invoked to process the "wm iconposition"
2213
 
 *      Tcl command.
 
2581
 *      This function is invoked to process the "wm iconposition" Tcl command.
2214
2582
 *      See the user documentation for details on what it does.
2215
2583
 *
2216
2584
 * Results:
2223
2591
 */
2224
2592
 
2225
2593
static int
2226
 
WmIconpositionCmd(tkwin, winPtr, interp, objc, objv)
2227
 
    Tk_Window tkwin;            /* Main window of the application. */
2228
 
    TkWindow *winPtr;           /* Toplevel to work with */
2229
 
    Tcl_Interp *interp;         /* Current interpreter. */
2230
 
    int objc;                   /* Number of arguments. */
2231
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2594
WmIconpositionCmd(
 
2595
    Tk_Window tkwin,            /* Main window of the application. */
 
2596
    TkWindow *winPtr,           /* Toplevel to work with */
 
2597
    Tcl_Interp *interp,         /* Current interpreter. */
 
2598
    int objc,                   /* Number of arguments. */
 
2599
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2232
2600
{
2233
2601
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2234
2602
    int x, y;
2239
2607
    }
2240
2608
    if (objc == 3) {
2241
2609
        if (wmPtr->hints.flags & IconPositionHint) {
2242
 
            char buf[TCL_INTEGER_SPACE * 2];
2243
 
 
2244
 
            sprintf(buf, "%d %d", wmPtr->hints.icon_x,
2245
 
                    wmPtr->hints.icon_y);
2246
 
            Tcl_SetResult(interp, buf, TCL_VOLATILE);
 
2610
            Tcl_IntResults(interp, 2, 0, wmPtr->hints.icon_x,
 
2611
                           wmPtr->hints.icon_y);
2247
2612
        }
2248
2613
        return TCL_OK;
2249
2614
    }
2267
2632
 *
2268
2633
 * WmIconwindowCmd --
2269
2634
 *
2270
 
 *      This procedure is invoked to process the "wm iconwindow" Tcl command.
 
2635
 *      This function is invoked to process the "wm iconwindow" Tcl command.
2271
2636
 *      See the user documentation for details on what it does.
2272
2637
 *
2273
2638
 * Results:
2280
2645
 */
2281
2646
 
2282
2647
static int
2283
 
WmIconwindowCmd(tkwin, winPtr, interp, objc, objv)
2284
 
    Tk_Window tkwin;            /* Main window of the application. */
2285
 
    TkWindow *winPtr;           /* Toplevel to work with */
2286
 
    Tcl_Interp *interp;         /* Current interpreter. */
2287
 
    int objc;                   /* Number of arguments. */
2288
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2648
WmIconwindowCmd(
 
2649
    Tk_Window tkwin,            /* Main window of the application. */
 
2650
    TkWindow *winPtr,           /* Toplevel to work with */
 
2651
    Tcl_Interp *interp,         /* Current interpreter. */
 
2652
    int objc,                   /* Number of arguments. */
 
2653
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2289
2654
{
2290
2655
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2291
2656
    Tk_Window tkwin2;
2306
2671
        wmPtr->hints.flags &= ~IconWindowHint;
2307
2672
        if (wmPtr->icon != NULL) {
2308
2673
            /*
2309
 
             * Remove the icon window relationship.  In principle we
2310
 
             * should also re-enable button events for the window, but
2311
 
             * this doesn't work in general because the window manager
2312
 
             * is probably selecting on them (we'll get an error if
2313
 
             * we try to re-enable the events).  So, just leave the
2314
 
             * icon window event-challenged;  the user will have to
2315
 
             * recreate it if they want button events.
 
2674
             * Remove the icon window relationship. In principle we should
 
2675
             * also re-enable button events for the window, but this doesn't
 
2676
             * work in general because the window manager is probably
 
2677
             * selecting on them (we'll get an error if we try to re-enable
 
2678
             * the events). So, just leave the icon window event-challenged;
 
2679
             * the user will have to recreate it if they want button events.
2316
2680
             */
2317
2681
 
2318
2682
            wmPtr2 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
2327
2691
        }
2328
2692
        if (!Tk_IsTopLevel(tkwin2)) {
2329
2693
            Tcl_AppendResult(interp, "can't use ", Tcl_GetString(objv[3]),
2330
 
                    " as icon window: not at top level", (char *) NULL);
 
2694
                    " as icon window: not at top level", NULL);
2331
2695
            return TCL_ERROR;
2332
2696
        }
2333
2697
        wmPtr2 = ((TkWindow *) tkwin2)->wmInfoPtr;
2334
2698
        if (wmPtr2->iconFor != NULL) {
2335
2699
            Tcl_AppendResult(interp, Tcl_GetString(objv[3]),
2336
 
                    " is already an icon for ",
2337
 
                    Tk_PathName(wmPtr2->iconFor), (char *) NULL);
 
2700
                    " is already an icon for ", Tk_PathName(wmPtr2->iconFor),
 
2701
                    NULL);
2338
2702
            return TCL_ERROR;
2339
2703
        }
2340
2704
        if (wmPtr->icon != NULL) {
2345
2709
        }
2346
2710
 
2347
2711
        /*
2348
 
         * Disable button events in the icon window:  some window
2349
 
         * managers (like olvwm) want to get the events themselves,
2350
 
         * but X only allows one application at a time to receive
2351
 
         * button events for a window.
 
2712
         * Disable button events in the icon window: some window managers
 
2713
         * (like olvwm) want to get the events themselves, but X only allows
 
2714
         * one application at a time to receive button events for a window.
2352
2715
         */
2353
2716
 
2354
2717
        atts.event_mask = Tk_Attributes(tkwin2)->event_mask
2384
2747
 *
2385
2748
 * WmMaxsizeCmd --
2386
2749
 *
2387
 
 *      This procedure is invoked to process the "wm maxsize" Tcl command.
2388
 
 *      See the user documentation for details on what it does.
 
2750
 *      This function is invoked to process the "wm maxsize" Tcl command. See
 
2751
 *      the user documentation for details on what it does.
2389
2752
 *
2390
2753
 * Results:
2391
2754
 *      A standard Tcl result.
2397
2760
 */
2398
2761
 
2399
2762
static int
2400
 
WmMaxsizeCmd(tkwin, winPtr, interp, objc, objv)
2401
 
    Tk_Window tkwin;            /* Main window of the application. */
2402
 
    TkWindow *winPtr;           /* Toplevel to work with */
2403
 
    Tcl_Interp *interp;         /* Current interpreter. */
2404
 
    int objc;                   /* Number of arguments. */
2405
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2763
WmMaxsizeCmd(
 
2764
    Tk_Window tkwin,            /* Main window of the application. */
 
2765
    TkWindow *winPtr,           /* Toplevel to work with */
 
2766
    Tcl_Interp *interp,         /* Current interpreter. */
 
2767
    int objc,                   /* Number of arguments. */
 
2768
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2406
2769
{
2407
2770
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2408
2771
    int width, height;
2440
2803
 *
2441
2804
 * WmMinsizeCmd --
2442
2805
 *
2443
 
 *      This procedure is invoked to process the "wm minsize" Tcl command.
2444
 
 *      See the user documentation for details on what it does.
 
2806
 *      This function is invoked to process the "wm minsize" Tcl command. See
 
2807
 *      the user documentation for details on what it does.
2445
2808
 *
2446
2809
 * Results:
2447
2810
 *      A standard Tcl result.
2453
2816
 */
2454
2817
 
2455
2818
static int
2456
 
WmMinsizeCmd(tkwin, winPtr, interp, objc, objv)
2457
 
    Tk_Window tkwin;            /* Main window of the application. */
2458
 
    TkWindow *winPtr;           /* Toplevel to work with */
2459
 
    Tcl_Interp *interp;         /* Current interpreter. */
2460
 
    int objc;                   /* Number of arguments. */
2461
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2819
WmMinsizeCmd(
 
2820
    Tk_Window tkwin,            /* Main window of the application. */
 
2821
    TkWindow *winPtr,           /* Toplevel to work with */
 
2822
    Tcl_Interp *interp,         /* Current interpreter. */
 
2823
    int objc,                   /* Number of arguments. */
 
2824
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2462
2825
{
2463
2826
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2464
2827
    int width, height;
2487
2850
 *
2488
2851
 * WmOverrideredirectCmd --
2489
2852
 *
2490
 
 *      This procedure is invoked to process the "wm overrideredirect"
2491
 
 *      Tcl command.
2492
 
 *      See the user documentation for details on what it does.
 
2853
 *      This function is invoked to process the "wm overrideredirect" Tcl
 
2854
 *      command. See the user documentation for details on what it does.
2493
2855
 *
2494
2856
 * Results:
2495
2857
 *      A standard Tcl result.
2501
2863
 */
2502
2864
 
2503
2865
static int
2504
 
WmOverrideredirectCmd(tkwin, winPtr, interp, objc, objv)
2505
 
    Tk_Window tkwin;            /* Main window of the application. */
2506
 
    TkWindow *winPtr;           /* Toplevel to work with */
2507
 
    Tcl_Interp *interp;         /* Current interpreter. */
2508
 
    int objc;                   /* Number of arguments. */
2509
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2866
WmOverrideredirectCmd(
 
2867
    Tk_Window tkwin,            /* Main window of the application. */
 
2868
    TkWindow *winPtr,           /* Toplevel to work with */
 
2869
    Tcl_Interp *interp,         /* Current interpreter. */
 
2870
    int objc,                   /* Number of arguments. */
 
2871
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2510
2872
{
2511
2873
    int boolean, curValue;
2512
2874
    XSetWindowAttributes atts;
2525
2887
    }
2526
2888
    if (curValue != boolean) {
2527
2889
        /*
2528
 
         * Only do this if we are really changing value, because it
2529
 
         * causes some funky stuff to occur
 
2890
         * Only do this if we are really changing value, because it causes
 
2891
         * some funky stuff to occur
2530
2892
         */
 
2893
 
2531
2894
        atts.override_redirect = (boolean) ? True : False;
2532
2895
        atts.save_under = (boolean) ? True : False;
2533
2896
 
2547
2910
 *
2548
2911
 * WmPositionfromCmd --
2549
2912
 *
2550
 
 *      This procedure is invoked to process the "wm positionfrom"
2551
 
 *      Tcl command.
 
2913
 *      This function is invoked to process the "wm positionfrom" Tcl command.
2552
2914
 *      See the user documentation for details on what it does.
2553
2915
 *
2554
2916
 * Results:
2561
2923
 */
2562
2924
 
2563
2925
static int
2564
 
WmPositionfromCmd(tkwin, winPtr, interp, objc, objv)
2565
 
    Tk_Window tkwin;            /* Main window of the application. */
2566
 
    TkWindow *winPtr;           /* Toplevel to work with */
2567
 
    Tcl_Interp *interp;         /* Current interpreter. */
2568
 
    int objc;                   /* Number of arguments. */
2569
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2926
WmPositionfromCmd(
 
2927
    Tk_Window tkwin,            /* Main window of the application. */
 
2928
    TkWindow *winPtr,           /* Toplevel to work with */
 
2929
    Tcl_Interp *interp,         /* Current interpreter. */
 
2930
    int objc,                   /* Number of arguments. */
 
2931
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2570
2932
{
2571
2933
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2572
2934
    static CONST char *optionStrings[] = {
2573
 
        "program", "user", (char *) NULL };
 
2935
        "program", "user", NULL };
2574
2936
    enum options {
2575
2937
        OPT_PROGRAM, OPT_USER };
2576
2938
    int index;
2612
2974
 *
2613
2975
 * WmProtocolCmd --
2614
2976
 *
2615
 
 *      This procedure is invoked to process the "wm protocol" Tcl command.
2616
 
 *      See the user documentation for details on what it does.
 
2977
 *      This function is invoked to process the "wm protocol" Tcl command. See
 
2978
 *      the user documentation for details on what it does.
2617
2979
 *
2618
2980
 * Results:
2619
2981
 *      A standard Tcl result.
2625
2987
 */
2626
2988
 
2627
2989
static int
2628
 
WmProtocolCmd(tkwin, winPtr, interp, objc, objv)
2629
 
    Tk_Window tkwin;            /* Main window of the application. */
2630
 
    TkWindow *winPtr;           /* Toplevel to work with */
2631
 
    Tcl_Interp *interp;         /* Current interpreter. */
2632
 
    int objc;                   /* Number of arguments. */
2633
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
2990
WmProtocolCmd(
 
2991
    Tk_Window tkwin,            /* Main window of the application. */
 
2992
    TkWindow *winPtr,           /* Toplevel to work with */
 
2993
    Tcl_Interp *interp,         /* Current interpreter. */
 
2994
    int objc,                   /* Number of arguments. */
 
2995
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2634
2996
{
2635
2997
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2636
2998
    register ProtocolHandler *protPtr, *prevPtr;
2646
3008
        /*
2647
3009
         * Return a list of all defined protocols for the window.
2648
3010
         */
 
3011
 
2649
3012
        for (protPtr = wmPtr->protPtr; protPtr != NULL;
2650
 
             protPtr = protPtr->nextPtr) {
 
3013
                protPtr = protPtr->nextPtr) {
2651
3014
            Tcl_AppendElement(interp,
2652
3015
                    Tk_GetAtomName((Tk_Window) winPtr, protPtr->protocol));
2653
3016
        }
2658
3021
        /*
2659
3022
         * Return the command to handle a given protocol.
2660
3023
         */
 
3024
 
2661
3025
        for (protPtr = wmPtr->protPtr; protPtr != NULL;
2662
 
             protPtr = protPtr->nextPtr) {
 
3026
                protPtr = protPtr->nextPtr) {
2663
3027
            if (protPtr->protocol == protocol) {
2664
3028
                Tcl_SetObjResult(interp,LangCallbackObj(protPtr->command));
2665
3029
                return TCL_OK;
2669
3033
    }
2670
3034
 
2671
3035
    /*
2672
 
     * Delete any current protocol handler, then create a new
2673
 
     * one with the specified command, unless the command is
2674
 
     * empty.
 
3036
     * Delete any current protocol handler, then create a new one with the
 
3037
     * specified command, unless the command is empty.
2675
3038
     */
2676
3039
 
2677
3040
    for (protPtr = wmPtr->protPtr, prevPtr = NULL; protPtr != NULL;
2678
 
         prevPtr = protPtr, protPtr = protPtr->nextPtr) {
 
3041
            prevPtr = protPtr, protPtr = protPtr->nextPtr) {
2679
3042
        if (protPtr->protocol == protocol) {
2680
3043
            if (prevPtr == NULL) {
2681
3044
                wmPtr->protPtr = protPtr->nextPtr;
2714
3077
 *
2715
3078
 * WmResizableCmd --
2716
3079
 *
2717
 
 *      This procedure is invoked to process the "wm resizable" Tcl command.
 
3080
 *      This function is invoked to process the "wm resizable" Tcl command.
2718
3081
 *      See the user documentation for details on what it does.
2719
3082
 *
2720
3083
 * Results:
2727
3090
 */
2728
3091
 
2729
3092
static int
2730
 
WmResizableCmd(tkwin, winPtr, interp, objc, objv)
2731
 
    Tk_Window tkwin;            /* Main window of the application. */
2732
 
    TkWindow *winPtr;           /* Toplevel to work with */
2733
 
    Tcl_Interp *interp;         /* Current interpreter. */
2734
 
    int objc;                   /* Number of arguments. */
2735
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
3093
WmResizableCmd(
 
3094
    Tk_Window tkwin,            /* Main window of the application. */
 
3095
    TkWindow *winPtr,           /* Toplevel to work with */
 
3096
    Tcl_Interp *interp,         /* Current interpreter. */
 
3097
    int objc,                   /* Number of arguments. */
 
3098
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2736
3099
{
2737
3100
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2738
3101
    int width, height;
2742
3105
        return TCL_ERROR;
2743
3106
    }
2744
3107
    if (objc == 3) {
2745
 
        char buf[TCL_INTEGER_SPACE * 2];
2746
 
 
2747
 
        sprintf(buf, "%d %d",
2748
 
                (wmPtr->flags  & WM_WIDTH_NOT_RESIZABLE) ? 0 : 1,
2749
 
                (wmPtr->flags  & WM_HEIGHT_NOT_RESIZABLE) ? 0 : 1);
2750
 
        Tcl_SetResult(interp, buf, TCL_VOLATILE);
 
3108
        Tcl_IntResults(interp, 2, 0,
 
3109
                       (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) ? 0 : 1,
 
3110
                       (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) ? 0 : 1);
2751
3111
        return TCL_OK;
2752
3112
    }
2753
3113
    if ((Tcl_GetBooleanFromObj(interp, objv[3], &width) != TCL_OK)
2774
3134
 *
2775
3135
 * WmSizefromCmd --
2776
3136
 *
2777
 
 *      This procedure is invoked to process the "wm sizefrom" Tcl command.
2778
 
 *      See the user documentation for details on what it does.
 
3137
 *      This function is invoked to process the "wm sizefrom" Tcl command. See
 
3138
 *      the user documentation for details on what it does.
2779
3139
 *
2780
3140
 * Results:
2781
3141
 *      A standard Tcl result.
2787
3147
 */
2788
3148
 
2789
3149
static int
2790
 
WmSizefromCmd(tkwin, winPtr, interp, objc, objv)
2791
 
    Tk_Window tkwin;            /* Main window of the application. */
2792
 
    TkWindow *winPtr;           /* Toplevel to work with */
2793
 
    Tcl_Interp *interp;         /* Current interpreter. */
2794
 
    int objc;                   /* Number of arguments. */
2795
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
3150
WmSizefromCmd(
 
3151
    Tk_Window tkwin,            /* Main window of the application. */
 
3152
    TkWindow *winPtr,           /* Toplevel to work with */
 
3153
    Tcl_Interp *interp,         /* Current interpreter. */
 
3154
    int objc,                   /* Number of arguments. */
 
3155
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2796
3156
{
2797
3157
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2798
3158
    static CONST char *optionStrings[] = {
2799
 
        "program", "user", (char *) NULL };
 
3159
        "program", "user", NULL };
2800
3160
    enum options {
2801
3161
        OPT_PROGRAM, OPT_USER };
2802
3162
    int index;
2839
3199
 *
2840
3200
 * WmStackorderCmd --
2841
3201
 *
2842
 
 *      This procedure is invoked to process the "wm stackorder" Tcl command.
 
3202
 *      This function is invoked to process the "wm stackorder" Tcl command.
2843
3203
 *      See the user documentation for details on what it does.
2844
3204
 *
2845
3205
 * Results:
2852
3212
 */
2853
3213
 
2854
3214
static int
2855
 
WmStackorderCmd(tkwin, winPtr, interp, objc, objv)
2856
 
    Tk_Window tkwin;            /* Main window of the application. */
2857
 
    TkWindow *winPtr;           /* Toplevel to work with */
2858
 
    Tcl_Interp *interp;         /* Current interpreter. */
2859
 
    int objc;                   /* Number of arguments. */
2860
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
3215
WmStackorderCmd(
 
3216
    Tk_Window tkwin,            /* Main window of the application. */
 
3217
    TkWindow *winPtr,           /* Toplevel to work with */
 
3218
    Tcl_Interp *interp,         /* Current interpreter. */
 
3219
    int objc,                   /* Number of arguments. */
 
3220
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2861
3221
{
2862
3222
    TkWindow **windows, **window_ptr;
2863
3223
    static CONST char *optionStrings[] = {
2864
 
        "isabove", "isbelow", (char *) NULL };
 
3224
        "isabove", "isbelow", NULL };
2865
3225
    enum options {
2866
3226
        OPT_ISABOVE, OPT_ISBELOW };
2867
3227
    int index;
2874
3234
    if (objc == 3) {
2875
3235
        windows = TkWmStackorderToplevel(winPtr);
2876
3236
        if (windows == NULL) {
2877
 
            panic("TkWmStackorderToplevel failed");
 
3237
            Tcl_Panic("TkWmStackorderToplevel failed");
2878
3238
        } else {
2879
3239
            for (window_ptr = windows; *window_ptr ; window_ptr++) {
2880
3240
                Tcl_AppendElement(interp, (*window_ptr)->pathName);
2893
3253
 
2894
3254
        if (!Tk_IsTopLevel(winPtr2)) {
2895
3255
            Tcl_AppendResult(interp, "window \"", winPtr2->pathName,
2896
 
                    "\" isn't a top-level window", (char *) NULL);
 
3256
                    "\" isn't a top-level window", NULL);
2897
3257
            return TCL_ERROR;
2898
3258
        }
2899
3259
 
2900
3260
        if (!Tk_IsMapped(winPtr)) {
2901
3261
            Tcl_AppendResult(interp, "window \"", winPtr->pathName,
2902
 
                    "\" isn't mapped", (char *) NULL);
 
3262
                    "\" isn't mapped", NULL);
2903
3263
            return TCL_ERROR;
2904
3264
        }
2905
3265
 
2906
3266
        if (!Tk_IsMapped(winPtr2)) {
2907
3267
            Tcl_AppendResult(interp, "window \"", winPtr2->pathName,
2908
 
                    "\" isn't mapped", (char *) NULL);
 
3268
                    "\" isn't mapped", NULL);
2909
3269
            return TCL_ERROR;
2910
3270
        }
2911
3271
 
2912
3272
        /*
2913
 
         * Lookup stacking order of all toplevels that are children
2914
 
         * of "." and find the position of winPtr and winPtr2
2915
 
         * in the stacking order.
 
3273
         * Lookup stacking order of all toplevels that are children of "." and
 
3274
         * find the position of winPtr and winPtr2 in the stacking order.
2916
3275
         */
2917
3276
 
2918
3277
        windows = TkWmStackorderToplevel(winPtr->mainPtr->winPtr);
2919
3278
 
2920
3279
        if (windows == NULL) {
2921
 
            Tcl_AppendResult(interp, "TkWmStackorderToplevel failed",
2922
 
                    (char *) NULL);
 
3280
            Tcl_AppendResult(interp, "TkWmStackorderToplevel failed", NULL);
2923
3281
            return TCL_ERROR;
2924
3282
        } else {
2925
3283
            for (window_ptr = windows; *window_ptr ; window_ptr++) {
2926
 
                if (*window_ptr == winPtr)
 
3284
                if (*window_ptr == winPtr) {
2927
3285
                    index1 = (window_ptr - windows);
2928
 
                if (*window_ptr == winPtr2)
 
3286
                }
 
3287
                if (*window_ptr == winPtr2) {
2929
3288
                    index2 = (window_ptr - windows);
2930
 
            }
2931
 
            if (index1 == -1)
2932
 
                panic("winPtr window not found");
2933
 
            if (index2 == -1)
2934
 
                panic("winPtr2 window not found");
 
3289
                }
 
3290
            }
 
3291
            if (index1 == -1) {
 
3292
                Tcl_Panic("winPtr window not found");
 
3293
            }
 
3294
            if (index2 == -1) {
 
3295
                Tcl_Panic("winPtr2 window not found");
 
3296
            }
2935
3297
 
2936
3298
            ckfree((char *) windows);
2937
3299
        }
2956
3318
 *
2957
3319
 * WmStateCmd --
2958
3320
 *
2959
 
 *      This procedure is invoked to process the "wm state" Tcl command.
2960
 
 *      See the user documentation for details on what it does.
 
3321
 *      This function is invoked to process the "wm state" Tcl command. See
 
3322
 *      the user documentation for details on what it does.
2961
3323
 *
2962
3324
 * Results:
2963
3325
 *      A standard Tcl result.
2969
3331
 */
2970
3332
 
2971
3333
static int
2972
 
WmStateCmd(tkwin, winPtr, interp, objc, objv)
2973
 
    Tk_Window tkwin;            /* Main window of the application. */
2974
 
    TkWindow *winPtr;           /* Toplevel to work with */
2975
 
    Tcl_Interp *interp;         /* Current interpreter. */
2976
 
    int objc;                   /* Number of arguments. */
2977
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
3334
WmStateCmd(
 
3335
    Tk_Window tkwin,            /* Main window of the application. */
 
3336
    TkWindow *winPtr,           /* Toplevel to work with */
 
3337
    Tcl_Interp *interp,         /* Current interpreter. */
 
3338
    int objc,                   /* Number of arguments. */
 
3339
    Tcl_Obj *CONST objv[])      /* Argument objects. */
2978
3340
{
2979
3341
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
2980
3342
    static CONST char *optionStrings[] = {
2981
 
        "normal", "iconic", "withdrawn", (char *) NULL };
 
3343
        "normal", "iconic", "withdrawn", NULL };
2982
3344
    enum options {
2983
3345
        OPT_NORMAL, OPT_ICONIC, OPT_WITHDRAWN };
2984
3346
    int index;
2990
3352
    if (objc == 4) {
2991
3353
        if (wmPtr->iconFor != NULL) {
2992
3354
            Tcl_AppendResult(interp, "can't change state of ",
2993
 
                    Tcl_GetString(objv[2]),
2994
 
                    ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
2995
 
                    (char *) NULL);
 
3355
                    Tcl_GetString(objv[2]), ": it is an icon for ",
 
3356
                    Tk_PathName(wmPtr->iconFor), NULL);
2996
3357
            return TCL_ERROR;
2997
3358
        }
2998
3359
 
3006
3367
            (void) TkpWmSetState(winPtr, NormalState);
3007
3368
        } else if (index == OPT_ICONIC) {
3008
3369
            if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
3009
 
                Tcl_AppendResult(interp, "can't iconify \"",
3010
 
                        winPtr->pathName,
3011
 
                        "\": override-redirect flag is set",
3012
 
                        (char *) NULL);
 
3370
                Tcl_AppendResult(interp, "can't iconify \"", winPtr->pathName,
 
3371
                        "\": override-redirect flag is set", NULL);
3013
3372
                return TCL_ERROR;
3014
3373
            }
3015
3374
            if (wmPtr->masterPtr != NULL) {
3016
 
                Tcl_AppendResult(interp, "can't iconify \"",
3017
 
                        winPtr->pathName,
3018
 
                        "\": it is a transient", (char *) NULL);
 
3375
                Tcl_AppendResult(interp, "can't iconify \"", winPtr->pathName,
 
3376
                        "\": it is a transient", NULL);
3019
3377
                return TCL_ERROR;
3020
3378
            }
3021
3379
            if (TkpWmSetState(winPtr, IconicState) == 0) {
3054
3412
 *
3055
3413
 * WmTitleCmd --
3056
3414
 *
3057
 
 *      This procedure is invoked to process the "wm title" Tcl command.
3058
 
 *      See the user documentation for details on what it does.
 
3415
 *      This function is invoked to process the "wm title" Tcl command. See
 
3416
 *      the user documentation for details on what it does.
3059
3417
 *
3060
3418
 * Results:
3061
3419
 *      A standard Tcl result.
3067
3425
 */
3068
3426
 
3069
3427
static int
3070
 
WmTitleCmd(tkwin, winPtr, interp, objc, objv)
3071
 
    Tk_Window tkwin;            /* Main window of the application. */
3072
 
    TkWindow *winPtr;           /* Toplevel to work with */
3073
 
    Tcl_Interp *interp;         /* Current interpreter. */
3074
 
    int objc;                   /* Number of arguments. */
3075
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
3428
WmTitleCmd(
 
3429
    Tk_Window tkwin,            /* Main window of the application. */
 
3430
    TkWindow *winPtr,           /* Toplevel to work with */
 
3431
    Tcl_Interp *interp,         /* Current interpreter. */
 
3432
    int objc,                   /* Number of arguments. */
 
3433
    Tcl_Obj *CONST objv[])      /* Argument objects. */
3076
3434
{
3077
3435
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
3078
3436
    char *argv3;
3096
3454
        strcpy(wmPtr->title, argv3);
3097
3455
 
3098
3456
        if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
3099
 
            XTextProperty textProp;
3100
 
            Tcl_DString ds;
3101
 
            char *string;
3102
 
 
3103
 
            Tcl_UtfToExternalDString(NULL, wmPtr->title, -1, &ds);
3104
 
            string = Tcl_DStringValue(&ds);
3105
 
            if (XStringListToTextProperty(&string, 1,
3106
 
                    &textProp)  != 0) {
3107
 
                XSetWMName(winPtr->display, wmPtr->wrapperPtr->window,
3108
 
                        &textProp);
3109
 
                XFree((char *) textProp.value);
3110
 
            }
3111
 
            Tcl_DStringFree(&ds);
 
3457
            UpdateTitle(winPtr);
3112
3458
        }
3113
3459
    }
3114
3460
    return TCL_OK;
3119
3465
 *
3120
3466
 * WmTransientCmd --
3121
3467
 *
3122
 
 *      This procedure is invoked to process the "wm transient" Tcl command.
 
3468
 *      This function is invoked to process the "wm transient" Tcl command.
3123
3469
 *      See the user documentation for details on what it does.
3124
3470
 *
3125
3471
 * Results:
3132
3478
 */
3133
3479
 
3134
3480
static int
3135
 
WmTransientCmd(tkwin, winPtr, interp, objc, objv)
3136
 
    Tk_Window tkwin;            /* Main window of the application. */
3137
 
    TkWindow *winPtr;           /* Toplevel to work with */
3138
 
    Tcl_Interp *interp;         /* Current interpreter. */
3139
 
    int objc;                   /* Number of arguments. */
3140
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
3481
WmTransientCmd(
 
3482
    Tk_Window tkwin,            /* Main window of the application. */
 
3483
    TkWindow *winPtr,           /* Toplevel to work with */
 
3484
    Tcl_Interp *interp,         /* Current interpreter. */
 
3485
    int objc,                   /* Number of arguments. */
 
3486
    Tcl_Obj *CONST objv[])      /* Argument objects. */
3141
3487
{
3142
3488
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
3143
3489
    TkWindow *masterPtr = wmPtr->masterPtr;
3157
3503
    if (Tcl_GetString(objv[3])[0] == '\0') {
3158
3504
        if (masterPtr != NULL) {
3159
3505
            /*
3160
 
             * If we had a master, tell them that we aren't tied
3161
 
             * to them anymore
 
3506
             * If we had a master, tell them that we aren't tied to them
 
3507
             * anymore
3162
3508
             */
3163
3509
 
3164
3510
            masterPtr->wmInfoPtr->numTransients--;
3165
 
            Tk_DeleteEventHandler((Tk_Window) masterPtr,
3166
 
                    StructureNotifyMask,
 
3511
            Tk_DeleteEventHandler((Tk_Window) masterPtr, StructureNotifyMask,
3167
3512
                    WmWaitMapProc, (ClientData) winPtr);
3168
3513
 
3169
 
            /* FIXME: Need a call like Win32's UpdateWrapper() so
3170
 
               we can recreate the wrapper and get rid of the
3171
 
               transient window decorations. */
 
3514
            /*
 
3515
             * FIXME: Need a call like Win32's UpdateWrapper() so we can
 
3516
             * recreate the wrapper and get rid of the transient window
 
3517
             * decorations.
 
3518
             */
3172
3519
        }
3173
3520
 
3174
3521
        wmPtr->masterPtr = NULL;
3187
3534
        Tk_MakeWindowExist((Tk_Window) masterPtr);
3188
3535
 
3189
3536
        if (wmPtr->iconFor != NULL) {
3190
 
            Tcl_AppendResult(interp, "can't make \"",
3191
 
                    Tcl_GetString(objv[2]),
 
3537
            Tcl_AppendResult(interp, "can't make \"", Tcl_GetString(objv[2]),
3192
3538
                    "\" a transient: it is an icon for ",
3193
 
                    Tk_PathName(wmPtr->iconFor),
3194
 
                    (char *) NULL);
 
3539
                    Tk_PathName(wmPtr->iconFor), NULL);
3195
3540
            return TCL_ERROR;
3196
3541
        }
3197
3542
 
3201
3546
        }
3202
3547
 
3203
3548
        if (wmPtr2->iconFor != NULL) {
3204
 
            Tcl_AppendResult(interp, "can't make \"",
3205
 
                    Tcl_GetString(objv[3]),
 
3549
            Tcl_AppendResult(interp, "can't make \"", Tcl_GetString(objv[3]),
3206
3550
                    "\" a master: it is an icon for ",
3207
 
                    Tk_PathName(wmPtr2->iconFor),
3208
 
                    (char *) NULL);
 
3551
                    Tk_PathName(wmPtr2->iconFor), NULL);
3209
3552
            return TCL_ERROR;
3210
3553
        }
3211
3554
 
3212
3555
        if (masterPtr == winPtr) {
3213
3556
            Tcl_AppendResult(interp, "can't make \"", Tk_PathName(winPtr),
3214
 
                    "\" its own master",
3215
 
                    (char *) NULL);
 
3557
                    "\" its own master", NULL);
3216
3558
            return TCL_ERROR;
3217
3559
        } else if (masterPtr != wmPtr->masterPtr) {
3218
3560
            /*
3219
 
             * Remove old master map/unmap binding before setting
3220
 
             * the new master. The event handler will ensure that
3221
 
             * transient states reflect the state of the master.
 
3561
             * Remove old master map/unmap binding before setting the new
 
3562
             * master. The event handler will ensure that transient states
 
3563
             * reflect the state of the master.
3222
3564
             */
3223
3565
 
3224
3566
            if (wmPtr->masterPtr != NULL) {
3230
3572
 
3231
3573
            masterPtr->wmInfoPtr->numTransients++;
3232
3574
            Tk_CreateEventHandler((Tk_Window) masterPtr,
3233
 
                    StructureNotifyMask,
3234
 
                    WmWaitMapProc, (ClientData) winPtr);
 
3575
                    StructureNotifyMask, WmWaitMapProc, (ClientData) winPtr);
3235
3576
 
3236
3577
            wmPtr->masterPtr = masterPtr;
3237
3578
        }
3245
3586
                return TCL_ERROR;
3246
3587
            }
3247
3588
        } else {
3248
 
            Window xwin = (wmPtr->masterPtr == NULL) ? None :
3249
 
                    wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window;
3250
 
            XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
3251
 
                    xwin);
 
3589
            if (wmPtr->masterPtr != NULL) {
 
3590
                XSetTransientForHint(winPtr->display,
 
3591
                        wmPtr->wrapperPtr->window,
 
3592
                        wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window);
 
3593
            } else {
 
3594
                XDeleteProperty(winPtr->display, wmPtr->wrapperPtr->window,
 
3595
                        Tk_InternAtom((Tk_Window)winPtr, "WM_TRANSIENT_FOR"));
 
3596
            }
3252
3597
        }
3253
3598
    }
3254
3599
    return TCL_OK;
3259
3604
 *
3260
3605
 * WmWithdrawCmd --
3261
3606
 *
3262
 
 *      This procedure is invoked to process the "wm withdraw" Tcl command.
3263
 
 *      See the user documentation for details on what it does.
 
3607
 *      This function is invoked to process the "wm withdraw" Tcl command. See
 
3608
 *      the user documentation for details on what it does.
3264
3609
 *
3265
3610
 * Results:
3266
3611
 *      A standard Tcl result.
3272
3617
 */
3273
3618
 
3274
3619
static int
3275
 
WmWithdrawCmd(tkwin, winPtr, interp, objc, objv)
3276
 
    Tk_Window tkwin;            /* Main window of the application. */
3277
 
    TkWindow *winPtr;           /* Toplevel to work with */
3278
 
    Tcl_Interp *interp;         /* Current interpreter. */
3279
 
    int objc;                   /* Number of arguments. */
3280
 
    Tcl_Obj *CONST objv[];      /* Argument objects. */
 
3620
WmWithdrawCmd(
 
3621
    Tk_Window tkwin,            /* Main window of the application. */
 
3622
    TkWindow *winPtr,           /* Toplevel to work with */
 
3623
    Tcl_Interp *interp,         /* Current interpreter. */
 
3624
    int objc,                   /* Number of arguments. */
 
3625
    Tcl_Obj *CONST objv[])      /* Argument objects. */
3281
3626
{
3282
3627
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
3283
3628
 
3287
3632
    }
3288
3633
    if (wmPtr->iconFor != NULL) {
3289
3634
        Tcl_AppendResult(interp, "can't withdraw ", Tcl_GetString(objv[2]),
3290
 
                ": it is an icon for ", Tk_PathName(wmPtr->iconFor),
3291
 
                (char *) NULL);
 
3635
                ": it is an icon for ", Tk_PathName(wmPtr->iconFor), NULL);
3292
3636
        return TCL_ERROR;
3293
3637
    }
3294
3638
    wmPtr->flags |= WM_WITHDRAWN;
3302
3646
}
3303
3647
 
3304
3648
/*
3305
 
 * Invoked by those wm subcommands that affect geometry.
3306
 
 * Schedules a geometry update.
 
3649
 * Invoked by those wm subcommands that affect geometry. Schedules a geometry
 
3650
 * update.
3307
3651
 */
 
3652
 
3308
3653
static void
3309
 
WmUpdateGeom(wmPtr, winPtr)
3310
 
    WmInfo *wmPtr;
3311
 
    TkWindow *winPtr;
 
3654
WmUpdateGeom(
 
3655
    WmInfo *wmPtr,
 
3656
    TkWindow *winPtr)
3312
3657
{
3313
3658
    if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
3314
3659
        Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr);
3317
3662
}
3318
3663
 
3319
3664
/*
3320
 
 * Invoked when a MapNotify or UnmapNotify event is delivered for a
3321
 
 * toplevel that is the master of a transient toplevel.
 
3665
 * Invoked when a MapNotify or UnmapNotify event is delivered for a toplevel
 
3666
 * that is the master of a transient toplevel.
3322
3667
 */
 
3668
 
3323
3669
static void
3324
 
WmWaitMapProc(clientData, eventPtr)
3325
 
    ClientData clientData;      /* Pointer to window. */
3326
 
    XEvent *eventPtr;           /* Information about event. */
 
3670
WmWaitMapProc(
 
3671
    ClientData clientData,      /* Pointer to window. */
 
3672
    XEvent *eventPtr)           /* Information about event. */
3327
3673
{
3328
3674
    TkWindow *winPtr = (TkWindow *) clientData;
3329
3675
    TkWindow *masterPtr = winPtr->wmInfoPtr->masterPtr;
3330
3676
 
3331
 
    if (masterPtr == NULL)
3332
 
        return;
 
3677
    if (masterPtr == NULL) {
 
3678
        return;
 
3679
    }
3333
3680
 
3334
3681
    if (eventPtr->type == MapNotify) {
3335
 
        if (!(winPtr->wmInfoPtr->flags & WM_WITHDRAWN))
3336
 
            (void) TkpWmSetState(winPtr, NormalState);
 
3682
        if (!(winPtr->wmInfoPtr->flags & WM_WITHDRAWN)) {
 
3683
            (void) TkpWmSetState(winPtr, NormalState);
 
3684
        }
3337
3685
    } else if (eventPtr->type == UnmapNotify) {
3338
 
        (void) TkpWmSetState(winPtr, WithdrawnState);
 
3686
        (void) TkpWmSetState(winPtr, WithdrawnState);
3339
3687
    }
3340
3688
}
3341
3689
 
3344
3692
 *
3345
3693
 * Tk_SetGrid --
3346
3694
 *
3347
 
 *      This procedure is invoked by a widget when it wishes to set a grid
3348
 
 *      coordinate system that controls the size of a top-level window.
3349
 
 *      It provides a C interface equivalent to the "wm grid" command and
3350
 
 *      is usually asscoiated with the -setgrid option.
 
3695
 *      This function is invoked by a widget when it wishes to set a grid
 
3696
 *      coordinate system that controls the size of a top-level window. It
 
3697
 *      provides a C interface equivalent to the "wm grid" command and is
 
3698
 *      usually asscoiated with the -setgrid option.
3351
3699
 *
3352
3700
 * Results:
3353
3701
 *      None.
3354
3702
 *
3355
3703
 * Side effects:
3356
 
 *      Grid-related information will be passed to the window manager, so
3357
 
 *      that the top-level window associated with tkwin will resize on
3358
 
 *      even grid units.  If some other window already controls gridding
3359
 
 *      for the top-level window then this procedure call has no effect.
 
3704
 *      Grid-related information will be passed to the window manager, so that
 
3705
 *      the top-level window associated with tkwin will resize on even grid
 
3706
 *      units. If some other window already controls gridding for the
 
3707
 *      top-level window then this function call has no effect.
3360
3708
 *
3361
3709
 *----------------------------------------------------------------------
3362
3710
 */
3363
3711
 
3364
3712
void
3365
 
Tk_SetGrid(tkwin, reqWidth, reqHeight, widthInc, heightInc)
3366
 
    Tk_Window tkwin;            /* Token for window.  New window mgr info
3367
 
                                 * will be posted for the top-level window
 
3713
Tk_SetGrid(
 
3714
    Tk_Window tkwin,            /* Token for window. New window mgr info will
 
3715
                                 * be posted for the top-level window
3368
3716
                                 * associated with this window. */
3369
 
    int reqWidth;               /* Width (in grid units) corresponding to
3370
 
                                 * the requested geometry for tkwin. */
3371
 
    int reqHeight;              /* Height (in grid units) corresponding to
3372
 
                                 * the requested geometry for tkwin. */
3373
 
    int widthInc, heightInc;    /* Pixel increments corresponding to a
3374
 
                                 * change of one grid unit. */
 
3717
    int reqWidth,               /* Width (in grid units) corresponding to the
 
3718
                                 * requested geometry for tkwin. */
 
3719
    int reqHeight,              /* Height (in grid units) corresponding to the
 
3720
                                 * requested geometry for tkwin. */
 
3721
    int widthInc, int heightInc)/* Pixel increments corresponding to a change
 
3722
                                 * of one grid unit. */
3375
3723
{
3376
3724
    TkWindow *winPtr = (TkWindow *) tkwin;
3377
3725
    register WmInfo *wmPtr;
3378
3726
 
3379
3727
    /*
 
3728
     * Ensure widthInc and heightInc are greater than 0
 
3729
     */
 
3730
 
 
3731
    if (widthInc <= 0) {
 
3732
        widthInc = 1;
 
3733
    }
 
3734
    if (heightInc <= 0) {
 
3735
        heightInc = 1;
 
3736
    }
 
3737
 
 
3738
    /*
3380
3739
     * Find the top-level window for tkwin, plus the window manager
3381
3740
     * information.
3382
3741
     */
3410
3769
    }
3411
3770
 
3412
3771
    /*
3413
 
     * If gridding was previously off, then forget about any window
3414
 
     * size requests made by the user or via "wm geometry":  these are
3415
 
     * in pixel units and there's no easy way to translate them to
3416
 
     * grid units since the new requested size of the top-level window in
3417
 
     * pixels may not yet have been registered yet (it may filter up
3418
 
     * the hierarchy in DoWhenIdle handlers).  However, if the window
3419
 
     * has never been mapped yet then just leave the window size alone:
3420
 
     * assume that it is intended to be in grid units but just happened
3421
 
     * to have been specified before this procedure was called.
 
3772
     * If gridding was previously off, then forget about any window size
 
3773
     * requests made by the user or via "wm geometry": these are in pixel
 
3774
     * units and there's no easy way to translate them to grid units since the
 
3775
     * new requested size of the top-level window in pixels may not yet have
 
3776
     * been registered yet (it may filter up the hierarchy in DoWhenIdle
 
3777
     * handlers). However, if the window has never been mapped yet then just
 
3778
     * leave the window size alone: assume that it is intended to be in grid
 
3779
     * units but just happened to have been specified before this function was
 
3780
     * called.
3422
3781
     */
3423
3782
 
3424
3783
    if ((wmPtr->gridWin == NULL) && !(wmPtr->flags & WM_NEVER_MAPPED)) {
3427
3786
    }
3428
3787
 
3429
3788
    /*
3430
 
     * Set the new gridding information, and start the process of passing
3431
 
     * all of this information to the window manager.
 
3789
     * Set the new gridding information, and start the process of passing all
 
3790
     * of this information to the window manager.
3432
3791
     */
3433
3792
 
3434
3793
    wmPtr->gridWin = tkwin;
3449
3808
 *
3450
3809
 * Tk_UnsetGrid --
3451
3810
 *
3452
 
 *      This procedure cancels the effect of a previous call
3453
 
 *      to Tk_SetGrid.
 
3811
 *      This function cancels the effect of a previous call to Tk_SetGrid.
3454
3812
 *
3455
3813
 * Results:
3456
3814
 *      None.
3457
3815
 *
3458
3816
 * Side effects:
3459
3817
 *      If tkwin currently controls gridding for its top-level window,
3460
 
 *      gridding is cancelled for that top-level window;  if some other
3461
 
 *      window controls gridding then this procedure has no effect.
 
3818
 *      gridding is cancelled for that top-level window; if some other window
 
3819
 *      controls gridding then this function has no effect.
3462
3820
 *
3463
3821
 *----------------------------------------------------------------------
3464
3822
 */
3465
3823
 
3466
3824
void
3467
 
Tk_UnsetGrid(tkwin)
3468
 
    Tk_Window tkwin;            /* Token for window that is currently
 
3825
Tk_UnsetGrid(
 
3826
    Tk_Window tkwin)            /* Token for window that is currently
3469
3827
                                 * controlling gridding. */
3470
3828
{
3471
3829
    TkWindow *winPtr = (TkWindow *) tkwin;
3518
3876
 *
3519
3877
 * ConfigureEvent --
3520
3878
 *
3521
 
 *      This procedure is called to handle ConfigureNotify events on
3522
 
 *      wrapper windows.
 
3879
 *      This function is called to handle ConfigureNotify events on wrapper
 
3880
 *      windows.
3523
3881
 *
3524
3882
 * Results:
3525
3883
 *      None.
3526
3884
 *
3527
3885
 * Side effects:
3528
 
 *      Information gets updated in the WmInfo structure for the window
3529
 
 *      and the toplevel itself gets repositioned within the wrapper.
 
3886
 *      Information gets updated in the WmInfo structure for the window and
 
3887
 *      the toplevel itself gets repositioned within the wrapper.
3530
3888
 *
3531
3889
 *----------------------------------------------------------------------
3532
3890
 */
3533
3891
 
3534
3892
static void
3535
 
ConfigureEvent(wmPtr, configEventPtr)
3536
 
    WmInfo *wmPtr;                      /* Information about toplevel window. */
3537
 
    XConfigureEvent *configEventPtr;    /* Event that just occurred for
3538
 
                                         * wmPtr->wrapperPtr. */
 
3893
ConfigureEvent(
 
3894
    WmInfo *wmPtr,              /* Information about toplevel window. */
 
3895
    XConfigureEvent *configEventPtr)
 
3896
                                /* Event that just occurred for
 
3897
                                 * wmPtr->wrapperPtr. */
3539
3898
{
3540
3899
    TkWindow *wrapperPtr = wmPtr->wrapperPtr;
3541
3900
    TkWindow *winPtr = wmPtr->winPtr;
3543
3902
    Tk_ErrorHandler handler;
3544
3903
 
3545
3904
    /*
3546
 
     * Update size information from the event.  There are a couple of
3547
 
     * tricky points here:
 
3905
     * Update size information from the event. There are a couple of tricky
 
3906
     * points here:
3548
3907
     *
3549
 
     * 1. If the user changed the size externally then set wmPtr->width
3550
 
     *    and wmPtr->height just as if a "wm geometry" command had been
3551
 
     *    invoked with the same information.
3552
 
     * 2. However, if the size is changing in response to a request
3553
 
     *    coming from us (WM_SYNC_PENDING is set), then don't set wmPtr->width
3554
 
     *    or wmPtr->height if they were previously -1 (otherwise the
3555
 
     *    window will stop tracking geometry manager requests).
 
3908
     * 1. If the user changed the size externally then set wmPtr->width and
 
3909
     *    wmPtr->height just as if a "wm geometry" command had been invoked
 
3910
     *    with the same information.
 
3911
     * 2. However, if the size is changing in response to a request coming
 
3912
     *    from us (WM_SYNC_PENDING is set), then don't set wmPtr->width or
 
3913
     *    wmPtr->height if they were previously -1 (otherwise the window will
 
3914
     *    stop tracking geometry manager requests).
3556
3915
     */
3557
3916
 
3558
3917
    if (((wrapperPtr->changes.width != configEventPtr->width)
3559
3918
            || (wrapperPtr->changes.height != configEventPtr->height))
3560
 
            && !(wmPtr->flags & WM_SYNC_PENDING)){
 
3919
            && !(wmPtr->flags & WM_SYNC_PENDING)) {
3561
3920
        if (dispPtr->flags & TK_DISPLAY_WM_TRACING) {
3562
3921
            printf("TopLevelEventProc: user changed %s size to %dx%d\n",
3563
3922
                    winPtr->pathName, configEventPtr->width,
3566
3925
        if ((wmPtr->width == -1)
3567
3926
                && (configEventPtr->width == winPtr->reqWidth)) {
3568
3927
            /*
3569
 
             * Don't set external width, since the user didn't change it
3570
 
             * from what the widgets asked for.
 
3928
             * Don't set external width, since the user didn't change it from
 
3929
             * what the widgets asked for.
3571
3930
             */
3572
3931
        } else {
3573
3932
            /*
3574
3933
             * Note: if this window is embedded then don't set the external
3575
3934
             * size, since it came from the containing application, not the
3576
 
             * user.  In this case we want to keep sending our size requests
3577
 
             * to the containing application;  if the user fixes the size
3578
 
             * of that application then it will still percolate down to us
3579
 
             * in the right way.
 
3935
             * user. In this case we want to keep sending our size requests to
 
3936
             * the containing application; if the user fixes the size of that
 
3937
             * application then it will still percolate down to us in the
 
3938
             * right way.
3580
3939
             */
3581
3940
 
3582
3941
            if (!(winPtr->flags & TK_EMBEDDED)) {
3596
3955
                && (configEventPtr->height ==
3597
3956
                        (winPtr->reqHeight + wmPtr->menuHeight))) {
3598
3957
            /*
3599
 
             * Don't set external height, since the user didn't change it
3600
 
             * from what the widgets asked for.
 
3958
             * Don't set external height, since the user didn't change it from
 
3959
             * what the widgets asked for.
3601
3960
             */
3602
3961
        } else {
3603
3962
            /*
3604
 
             * See note for wmPtr->width about not setting external size
3605
 
             * for embedded windows.
 
3963
             * See note for wmPtr->width about not setting external size for
 
3964
             * embedded windows.
3606
3965
             */
3607
3966
 
3608
3967
            if (!(winPtr->flags & TK_EMBEDDED)) {
3616
3975
                } else {
3617
3976
                    wmPtr->height = configEventPtr->height - wmPtr->menuHeight;
3618
3977
                }
3619
 
            }
 
3978
            }
3620
3979
        }
3621
3980
        wmPtr->configWidth = configEventPtr->width;
3622
3981
        wmPtr->configHeight = configEventPtr->height;
3637
3996
    wrapperPtr->changes.stack_mode = Above;
3638
3997
 
3639
3998
    /*
3640
 
     * Reparenting window managers make life difficult.  If the
3641
 
     * window manager reparents a top-level window then the x and y
3642
 
     * information that comes in events for the window is wrong:
3643
 
     * it gives the location of the window inside its decorative
3644
 
     * parent, rather than the location of the window in root
3645
 
     * coordinates, which is what we want.  Window managers
3646
 
     * are supposed to send synthetic events with the correct
3647
 
     * information, but ICCCM doesn't require them to do this
3648
 
     * under all conditions, and the information provided doesn't
3649
 
     * include everything we need here.  So, the code below
3650
 
     * maintains a bunch of information about the parent window.
3651
 
     * If the window hasn't been reparented, we pretend that
3652
 
     * there is a parent shrink-wrapped around the window.
 
3999
     * Reparenting window managers make life difficult. If the window manager
 
4000
     * reparents a top-level window then the x and y information that comes in
 
4001
     * events for the window is wrong: it gives the location of the window
 
4002
     * inside its decorative parent, rather than the location of the window in
 
4003
     * root coordinates, which is what we want. Window managers are supposed
 
4004
     * to send synthetic events with the correct information, but ICCCM
 
4005
     * doesn't require them to do this under all conditions, and the
 
4006
     * information provided doesn't include everything we need here. So, the
 
4007
     * code below maintains a bunch of information about the parent window.
 
4008
     * If the window hasn't been reparented, we pretend that there is a parent
 
4009
     * shrink-wrapped around the window.
3653
4010
     */
3654
4011
 
3655
4012
    if (dispPtr->flags & TK_DISPLAY_WM_TRACING) {
3675
4032
 
3676
4033
    /*
3677
4034
     * Make sure that the toplevel and menubar are properly positioned within
3678
 
     * the wrapper.  If the menuHeight happens to be zero, we'll get a
3679
 
     * BadValue X error that we want to ignore [Bug: 3377]
 
4035
     * the wrapper. If the menuHeight happens to be zero, we'll get a BadValue
 
4036
     * X error that we want to ignore [Bug: 3377]
3680
4037
     */
3681
 
    handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1,
3682
 
            (Tk_ErrorProc *) NULL, (ClientData) NULL);
 
4038
 
 
4039
    handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1, NULL, NULL);
3683
4040
    XMoveResizeWindow(winPtr->display, winPtr->window, 0,
3684
4041
            wmPtr->menuHeight, (unsigned) wrapperPtr->changes.width,
3685
4042
            (unsigned) (wrapperPtr->changes.height - wmPtr->menuHeight));
3693
4050
 
3694
4051
    /*
3695
4052
     * Update the coordinates in the toplevel (they should refer to the
3696
 
     * position in root window coordinates, not the coordinates of the
3697
 
     * wrapper window).  Then synthesize a ConfigureNotify event to tell
3698
 
     * the application about the change.
 
4053
     * position in root window coordinates, not the coordinates of the wrapper
 
4054
     * window). Then synthesize a ConfigureNotify event to tell the
 
4055
     * application about the change.
3699
4056
     */
3700
4057
 
3701
4058
    winPtr->changes.x = wrapperPtr->changes.x;
3710
4067
 *
3711
4068
 * ReparentEvent --
3712
4069
 *
3713
 
 *      This procedure is called to handle ReparentNotify events on
3714
 
 *      wrapper windows.
 
4070
 *      This function is called to handle ReparentNotify events on wrapper
 
4071
 *      windows.
3715
4072
 *
3716
4073
 * Results:
3717
4074
 *      None.
3723
4080
 */
3724
4081
 
3725
4082
static void
3726
 
ReparentEvent(wmPtr, reparentEventPtr)
3727
 
    WmInfo *wmPtr;                      /* Information about toplevel window. */
3728
 
    XReparentEvent *reparentEventPtr;   /* Event that just occurred for
3729
 
                                         * wmPtr->wrapperPtr. */
 
4083
ReparentEvent(
 
4084
    WmInfo *wmPtr,              /* Information about toplevel window. */
 
4085
    XReparentEvent *reparentEventPtr)
 
4086
                                /* Event that just occurred for
 
4087
                                 * wmPtr->wrapperPtr. */
3730
4088
{
3731
4089
    TkWindow *wrapperPtr = wmPtr->wrapperPtr;
3732
4090
    Window vRoot, ancestor, *children, dummy2, *virtualRootPtr;
3738
4096
    TkDisplay *dispPtr = wmPtr->winPtr->dispPtr;
3739
4097
 
3740
4098
    /*
3741
 
     * Identify the root window for wrapperPtr.  This is tricky because of
3742
 
     * virtual root window managers like tvtwm.  If the window has a
3743
 
     * property named __SWM_ROOT or __WM_ROOT then this property gives
3744
 
     * the id for a virtual root window that should be used instead of
3745
 
     * the root window of the screen.
 
4099
     * Identify the root window for wrapperPtr. This is tricky because of
 
4100
     * virtual root window managers like tvtwm. If the window has a property
 
4101
     * named __SWM_ROOT or __WM_ROOT then this property gives the id for a
 
4102
     * virtual root window that should be used instead of the root window of
 
4103
     * the screen.
3746
4104
     */
3747
4105
 
3748
4106
    vRoot = RootWindow(wrapperPtr->display, wrapperPtr->screenNum);
3749
4107
    wmPtr->vRoot = None;
3750
 
    handler = Tk_CreateErrorHandler(wrapperPtr->display, -1, -1, -1,
3751
 
            (Tk_ErrorProc *) NULL, (ClientData) NULL);
 
4108
    handler = Tk_CreateErrorHandler(wrapperPtr->display, -1,-1,-1, NULL,NULL);
3752
4109
    if (((XGetWindowProperty(wrapperPtr->display, wrapperPtr->window,
3753
4110
            Tk_InternAtom((Tk_Window) wrapperPtr, "__WM_ROOT"), 0, (long) 1,
3754
4111
            False, XA_WINDOW, &actualType, &actualFormat, &numItems,
3783
4140
    UpdateVRootGeometry(wmPtr);
3784
4141
 
3785
4142
    /*
3786
 
     * If the window's new parent is the root window, then mark it as
3787
 
     * no longer reparented.
 
4143
     * If the window's new parent is the root window, then mark it as no
 
4144
     * longer reparented.
3788
4145
     */
3789
4146
 
3790
4147
    if (reparentEventPtr->parent == vRoot) {
3791
 
        noReparent:
 
4148
    noReparent:
3792
4149
        wmPtr->reparent = None;
3793
4150
        wmPtr->parentWidth = wrapperPtr->changes.width;
3794
4151
        wmPtr->parentHeight = wrapperPtr->changes.height;
3801
4158
    }
3802
4159
 
3803
4160
    /*
3804
 
     * Search up the window hierarchy to find the ancestor of this
3805
 
     * window that is just below the (virtual) root.  This is tricky
3806
 
     * because it's possible that things have changed since the event
3807
 
     * was generated so that the ancestry indicated by the event no
3808
 
     * longer exists.  If this happens then an error will occur and
3809
 
     * we just discard the event (there will be a more up-to-date
3810
 
     * ReparentNotify event coming later).
 
4161
     * Search up the window hierarchy to find the ancestor of this window that
 
4162
     * is just below the (virtual) root. This is tricky because it's possible
 
4163
     * that things have changed since the event was generated so that the
 
4164
     * ancestry indicated by the event no longer exists. If this happens then
 
4165
     * an error will occur and we just discard the event (there will be a more
 
4166
     * up-to-date ReparentNotify event coming later).
3811
4167
     */
3812
4168
 
3813
 
    handler = Tk_CreateErrorHandler(wrapperPtr->display, -1, -1, -1,
3814
 
            (Tk_ErrorProc *) NULL, (ClientData) NULL);
 
4169
    handler = Tk_CreateErrorHandler(wrapperPtr->display, -1,-1,-1, NULL,NULL);
3815
4170
    wmPtr->reparent = reparentEventPtr->parent;
3816
4171
    while (1) {
3817
4172
        if (XQueryTree(wrapperPtr->display, wmPtr->reparent, &dummy2,
3839
4194
 *
3840
4195
 * ComputeReparentGeometry --
3841
4196
 *
3842
 
 *      This procedure is invoked to recompute geometry information
3843
 
 *      related to a reparented top-level window, such as the position
3844
 
 *      and total size of the parent and the position within it of
3845
 
 *      the top-level window.
 
4197
 *      This function is invoked to recompute geometry information related to
 
4198
 *      a reparented top-level window, such as the position and total size of
 
4199
 *      the parent and the position within it of the top-level window.
3846
4200
 *
3847
4201
 * Results:
3848
 
 *      The return value is 1 if everything completed successfully
3849
 
 *      and 0 if an error occurred while querying information about
3850
 
 *      winPtr's parents.  In this case winPtr is marked as no longer
3851
 
 *      being reparented.
 
4202
 *      The return value is 1 if everything completed successfully and 0 if an
 
4203
 *      error occurred while querying information about winPtr's parents. In
 
4204
 *      this case winPtr is marked as no longer being reparented.
3852
4205
 *
3853
4206
 * Side effects:
3854
 
 *      Geometry information in wmPtr, wmPtr->winPtr, and
3855
 
 *      wmPtr->wrapperPtr gets updated.
 
4207
 *      Geometry information in wmPtr, wmPtr->winPtr, and wmPtr->wrapperPtr
 
4208
 *      gets updated.
3856
4209
 *
3857
4210
 *----------------------------------------------------------------------
3858
4211
 */
3859
4212
 
3860
4213
static int
3861
 
ComputeReparentGeometry(wmPtr)
3862
 
    WmInfo *wmPtr;              /* Information about toplevel window
3863
 
                                 * whose reparent info is to be recomputed. */
 
4214
ComputeReparentGeometry(
 
4215
    WmInfo *wmPtr)              /* Information about toplevel window whose
 
4216
                                 * reparent info is to be recomputed. */
3864
4217
{
3865
4218
    TkWindow *wrapperPtr = wmPtr->wrapperPtr;
3866
4219
    int width, height, bd;
3871
4224
    Tk_ErrorHandler handler;
3872
4225
    TkDisplay *dispPtr = wmPtr->winPtr->dispPtr;
3873
4226
 
3874
 
    handler = Tk_CreateErrorHandler(wrapperPtr->display, -1, -1, -1,
3875
 
            (Tk_ErrorProc *) NULL, (ClientData) NULL);
 
4227
    handler = Tk_CreateErrorHandler(wrapperPtr->display, -1,-1,-1, NULL,NULL);
3876
4228
    (void) XTranslateCoordinates(wrapperPtr->display, wrapperPtr->window,
3877
4229
            wmPtr->reparent, 0, 0, &xOffset, &yOffset, &dummy2);
3878
4230
    status = XGetGeometry(wrapperPtr->display, wmPtr->reparent,
3881
4233
    Tk_DeleteErrorHandler(handler);
3882
4234
    if (status == 0) {
3883
4235
        /*
3884
 
         * It appears that the reparented parent went away and
3885
 
         * no-one told us.  Reset the window to indicate that
3886
 
         * it's not reparented.
 
4236
         * It appears that the reparented parent went away and no-one told us.
 
4237
         * Reset the window to indicate that it's not reparented.
3887
4238
         */
 
4239
 
3888
4240
        wmPtr->reparent = None;
3889
4241
        wmPtr->xInParent = wmPtr->yInParent = 0;
3890
4242
        return 0;
3897
4249
    /*
3898
4250
     * Some tricky issues in updating wmPtr->x and wmPtr->y:
3899
4251
     *
3900
 
     * 1. Don't update them if the event occurred because of something
3901
 
     * we did (i.e. WM_SYNC_PENDING and WM_MOVE_PENDING are both set).
3902
 
     * This is because window managers treat coords differently than Tk,
3903
 
     * and no two window managers are alike. If the window manager moved
3904
 
     * the window because we told it to, remember the coordinates we told
3905
 
     * it, not the ones it actually moved it to.  This allows us to move
3906
 
     * the window back to the same coordinates later and get the same
3907
 
     * result. Without this check, windows can "walk" across the screen
3908
 
     * under some conditions.
3909
 
     *
3910
 
     * 2. Don't update wmPtr->x and wmPtr->y unless wrapperPtr->changes.x
3911
 
     * or wrapperPtr->changes.y has changed (otherwise a size change can
3912
 
     * spoof us into thinking that the position changed too and defeat
3913
 
     * the intent of (1) above.
3914
 
     *
3915
 
     * (As of 9/96 the above 2 comments appear to be stale.  They're
3916
 
     * being left in place as a reminder of what was once true (and
3917
 
     * perhaps should still be true?)).
3918
 
     *
3919
 
     * 3. Ignore size changes coming from the window system if we're
3920
 
     * about to change the size ourselves but haven't seen the event for
3921
 
     * it yet:  our size change is supposed to take priority.
 
4252
     * 1. Don't update them if the event occurred because of something we did
 
4253
     * (i.e. WM_SYNC_PENDING and WM_MOVE_PENDING are both set). This is
 
4254
     * because window managers treat coords differently than Tk, and no two
 
4255
     * window managers are alike. If the window manager moved the window
 
4256
     * because we told it to, remember the coordinates we told it, not the
 
4257
     * ones it actually moved it to. This allows us to move the window back to
 
4258
     * the same coordinates later and get the same result. Without this check,
 
4259
     * windows can "walk" across the screen under some conditions.
 
4260
     *
 
4261
     * 2. Don't update wmPtr->x and wmPtr->y unless wrapperPtr->changes.x or
 
4262
     * wrapperPtr->changes.y has changed (otherwise a size change can spoof us
 
4263
     * into thinking that the position changed too and defeat the intent of
 
4264
     * (1) above.
 
4265
     *
 
4266
     * (As of 9/96 the above 2 comments appear to be stale. They're being left
 
4267
     * in place as a reminder of what was once true (and perhaps should still
 
4268
     * be true?)).
 
4269
     *
 
4270
     * 3. Ignore size changes coming from the window system if we're about to
 
4271
     * change the size ourselves but haven't seen the event for it yet: our
 
4272
     * size change is supposed to take priority.
3922
4273
     */
3923
4274
 
3924
4275
    if (!(wmPtr->flags & WM_MOVE_PENDING)
3948
4299
/*
3949
4300
 *----------------------------------------------------------------------
3950
4301
 *
 
4302
 * PropertyEvent --
 
4303
 *
 
4304
 *      Handle PropertyNotify events on wrapper windows.
 
4305
 *      The following properties are of interest:
 
4306
 *
 
4307
 *      _NET_WM_STATE:
 
4308
 *              Used to keep wmPtr->attributes up to date.
 
4309
 *
 
4310
 *----------------------------------------------------------------------
 
4311
 */
 
4312
 
 
4313
static void
 
4314
PropertyEvent(
 
4315
    WmInfo *wmPtr,              /* Information about toplevel window. */
 
4316
    XPropertyEvent *eventPtr)   /* PropertyNotify event structure */
 
4317
{
 
4318
    TkWindow *wrapperPtr = wmPtr->wrapperPtr;
 
4319
    Atom _NET_WM_STATE =
 
4320
        Tk_InternAtom((Tk_Window)wmPtr->winPtr, "_NET_WM_STATE");
 
4321
 
 
4322
    if (eventPtr->atom == _NET_WM_STATE) {
 
4323
        Atom actualType;
 
4324
        int actualFormat;
 
4325
        unsigned long numItems, bytesAfter;
 
4326
        unsigned char *propertyValue = 0;
 
4327
        long maxLength = 1024;
 
4328
 
 
4329
        if (XGetWindowProperty(
 
4330
                wrapperPtr->display, wrapperPtr->window, _NET_WM_STATE,
 
4331
                0l, maxLength, False, XA_ATOM,
 
4332
                &actualType, &actualFormat, &numItems, &bytesAfter, 
 
4333
                &propertyValue) == Success
 
4334
        ) {
 
4335
            CheckNetWmState(wmPtr, (Atom*)propertyValue, (int)numItems);
 
4336
            XFree(propertyValue);
 
4337
        }
 
4338
    }
 
4339
}
 
4340
 
 
4341
/*
 
4342
 *----------------------------------------------------------------------
 
4343
 *
3951
4344
 * WrapperEventProc --
3952
4345
 *
3953
 
 *      This procedure is invoked by the event loop when a wrapper window
3954
 
 *      is restructured.
 
4346
 *      This function is invoked by the event loop when a wrapper window is
 
4347
 *      restructured.
3955
4348
 *
3956
4349
 * Results:
3957
4350
 *      None.
3958
4351
 *
3959
4352
 * Side effects:
3960
 
 *      Tk's internal data structures for the window get modified to
3961
 
 *      reflect the structural change.
 
4353
 *      Tk's internal data structures for the window get modified to reflect
 
4354
 *      the structural change.
3962
4355
 *
3963
4356
 *----------------------------------------------------------------------
3964
4357
 */
3965
4358
 
 
4359
static const unsigned int WrapperEventMask = 
 
4360
    (StructureNotifyMask | PropertyChangeMask);
 
4361
 
3966
4362
static void
3967
 
WrapperEventProc(clientData, eventPtr)
3968
 
    ClientData clientData;              /* Information about toplevel window. */
3969
 
    XEvent *eventPtr;                   /* Event that just happened. */
 
4363
WrapperEventProc(
 
4364
    ClientData clientData,      /* Information about toplevel window. */
 
4365
    XEvent *eventPtr)           /* Event that just happened. */
3970
4366
{
3971
4367
    WmInfo *wmPtr = (WmInfo *) clientData;
3972
4368
    XEvent mapEvent;
3979
4375
        if (!(wmPtr->wrapperPtr->flags & TK_ALREADY_DEAD)) {
3980
4376
            /*
3981
4377
             * A top-level window was deleted externally (e.g., by the window
3982
 
             * manager).  This is probably not a good thing, but cleanup as
3983
 
             * best we can.  The error handler is needed because
 
4378
             * manager). This is probably not a good thing, but cleanup as
 
4379
             * best we can. The error handler is needed because
3984
4380
             * Tk_DestroyWindow will try to destroy the window, but of course
3985
4381
             * it's already gone.
3986
4382
             */
3987
4383
 
3988
4384
            handler = Tk_CreateErrorHandler(wmPtr->winPtr->display, -1, -1, -1,
3989
 
                    (Tk_ErrorProc *) NULL, (ClientData) NULL);
 
4385
                    NULL, NULL);
3990
4386
            Tk_DestroyWindow((Tk_Window) wmPtr->winPtr);
3991
4387
            Tk_DeleteErrorHandler(handler);
3992
4388
        }
3995
4391
        }
3996
4392
    } else if (eventPtr->type == ConfigureNotify) {
3997
4393
        /*
3998
 
         * Ignore the event if the window has never been mapped yet.
3999
 
         * Such an event occurs only in weird cases like changing the
4000
 
         * internal border width of a top-level window, which results
4001
 
         * in a synthetic Configure event.  These events are not relevant
4002
 
         * to us, and if we process them confusion may result (e.g. we
4003
 
         * may conclude erroneously that the user repositioned or resized
4004
 
         * the window).
 
4394
         * Ignore the event if the window has never been mapped yet. Such an
 
4395
         * event occurs only in weird cases like changing the internal border
 
4396
         * width of a top-level window, which results in a synthetic Configure
 
4397
         * event. These events are not relevant to us, and if we process them
 
4398
         * confusion may result (e.g. we may conclude erroneously that the
 
4399
         * user repositioned or resized the window).
4005
4400
         */
4006
4401
 
4007
4402
        if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
4019
4414
        goto doMapEvent;
4020
4415
    } else if (eventPtr->type == ReparentNotify) {
4021
4416
        ReparentEvent(wmPtr, &eventPtr->xreparent);
 
4417
    } else if (eventPtr->type == PropertyNotify) {
 
4418
        PropertyEvent(wmPtr, &eventPtr->xproperty);
4022
4419
    } else if (0 && eventPtr->type == Expose) {
4023
4420
        mapEvent = *eventPtr;
4024
4421
        mapEvent.xexpose.window = wmPtr->winPtr->window;
4026
4423
    }
4027
4424
    return;
4028
4425
 
4029
 
    doMapEvent:
 
4426
  doMapEvent:
4030
4427
    mapEvent = *eventPtr;
4031
4428
    mapEvent.xmap.event = wmPtr->winPtr->window;
4032
4429
    mapEvent.xmap.window = wmPtr->winPtr->window;
4038
4435
 *
4039
4436
 * TopLevelReqProc --
4040
4437
 *
4041
 
 *      This procedure is invoked by the geometry manager whenever
4042
 
 *      the requested size for a top-level window is changed.
 
4438
 *      This function is invoked by the geometry manager whenever the
 
4439
 *      requested size for a top-level window is changed.
4043
4440
 *
4044
4441
 * Results:
4045
4442
 *      None.
4046
4443
 *
4047
4444
 * Side effects:
4048
 
 *      Arrange for the window to be resized to satisfy the request
4049
 
 *      (this happens as a when-idle action).
 
4445
 *      Arrange for the window to be resized to satisfy the request (this
 
4446
 *      happens as a when-idle action).
4050
4447
 *
4051
4448
 *----------------------------------------------------------------------
4052
4449
 */
4053
4450
 
4054
4451
        /* ARGSUSED */
4055
4452
static void
4056
 
TopLevelReqProc(dummy, tkwin)
4057
 
    ClientData dummy;                   /* Not used. */
4058
 
    Tk_Window tkwin;                    /* Information about window. */
 
4453
TopLevelReqProc(
 
4454
    ClientData dummy,           /* Not used. */
 
4455
    Tk_Window tkwin)            /* Information about window. */
4059
4456
{
4060
4457
    TkWindow *winPtr = (TkWindow *) tkwin;
4061
4458
    WmInfo *wmPtr;
4064
4461
 
4065
4462
    if ((wmPtr->width >= 0) && (wmPtr->height >= 0)) {
4066
4463
        /*
4067
 
         * Explicit dimensions have been set for this window, so we
4068
 
         * should ignore the geometry request.  It's actually important
4069
 
         * to ignore the geometry request because, due to quirks in
4070
 
         * window managers, invoking UpdateGeometryInfo may cause the
4071
 
         * window to move.  For example, if "wm geometry -10-20" was
4072
 
         * invoked, the window may be positioned incorrectly the first
4073
 
         * time it appears (because we didn't know the proper width of
4074
 
         * the window manager borders); if we invoke UpdateGeometryInfo
4075
 
         * again, the window will be positioned correctly, which may
4076
 
         * cause it to jump on the screen.
 
4464
         * Explicit dimensions have been set for this window, so we should
 
4465
         * ignore the geometry request. It's actually important to ignore the
 
4466
         * geometry request because, due to quirks in window managers,
 
4467
         * invoking UpdateGeometryInfo may cause the window to move. For
 
4468
         * example, if "wm geometry -10-20" was invoked, the window may be
 
4469
         * positioned incorrectly the first time it appears (because we didn't
 
4470
         * know the proper width of the window manager borders); if we invoke
 
4471
         * UpdateGeometryInfo again, the window will be positioned correctly,
 
4472
         * which may cause it to jump on the screen.
4077
4473
         */
4078
4474
 
4079
4475
        return;
4086
4482
    }
4087
4483
 
4088
4484
    /*
4089
 
     * If the window isn't being positioned by its upper left corner
4090
 
     * then we have to move it as well.
 
4485
     * If the window isn't being positioned by its upper left corner then we
 
4486
     * have to move it as well.
4091
4487
     */
4092
4488
 
4093
4489
    if (wmPtr->flags & (WM_NEGATIVE_X | WM_NEGATIVE_Y)) {
4100
4496
 *
4101
4497
 * UpdateGeometryInfo --
4102
4498
 *
4103
 
 *      This procedure is invoked when a top-level window is first
4104
 
 *      mapped, and also as a when-idle procedure, to bring the
4105
 
 *      geometry and/or position of a top-level window back into
4106
 
 *      line with what has been requested by the user and/or widgets.
4107
 
 *      This procedure doesn't return until the window manager has
4108
 
 *      responded to the geometry change.
 
4499
 *      This function is invoked when a top-level window is first mapped, and
 
4500
 *      also as a when-idle function, to bring the geometry and/or position of
 
4501
 *      a top-level window back into line with what has been requested by the
 
4502
 *      user and/or widgets. This function doesn't return until the window
 
4503
 *      manager has responded to the geometry change.
4109
4504
 *
4110
4505
 * Results:
4111
4506
 *      None.
4112
4507
 *
4113
4508
 * Side effects:
4114
 
 *      The size and location of both the toplevel window and its wrapper
4115
 
 *      may change, unless the WM prevents that from happening.
 
4509
 *      The size and location of both the toplevel window and its wrapper may
 
4510
 *      change, unless the WM prevents that from happening.
4116
4511
 *
4117
4512
 *----------------------------------------------------------------------
4118
4513
 */
4119
4514
 
4120
4515
static void
4121
 
UpdateGeometryInfo(clientData)
4122
 
    ClientData clientData;              /* Pointer to the window's record. */
 
4516
UpdateGeometryInfo(
 
4517
    ClientData clientData)      /* Pointer to the window's record. */
4123
4518
{
4124
4519
    register TkWindow *winPtr = (TkWindow *) clientData;
4125
4520
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
4126
 
    int x, y, width, height;
 
4521
    int x, y, width, height, min, max;
4127
4522
    unsigned long serial;
4128
4523
 
4129
4524
    wmPtr->flags &= ~WM_UPDATE_PENDING;
4130
4525
 
4131
4526
    /*
4132
 
     * Compute the new size for the top-level window.  See the
4133
 
     * user documentation for details on this, but the size
4134
 
     * requested depends on (a) the size requested internally
4135
 
     * by the window's widgets, (b) the size requested by the
4136
 
     * user in a "wm geometry" command or via wm-based interactive
4137
 
     * resizing (if any), and (c) whether or not the window is
4138
 
     * gridded.  Don't permit sizes <= 0 because this upsets
4139
 
     * the X server.
 
4527
     * Compute the new size for the top-level window. See the user
 
4528
     * documentation for details on this, but the size requested depends on
 
4529
     * (a) the size requested internally by the window's widgets, (b) the size
 
4530
     * requested by the user in a "wm geometry" command or via wm-based
 
4531
     * interactive resizing (if any), (c) whether or not the window is
 
4532
     * gridded, and (d) the current min or max size for the toplevel. Don't
 
4533
     * permit sizes <= 0 because this upsets the X server.
4140
4534
     */
4141
4535
 
4142
4536
    if (wmPtr->width == -1) {
4150
4544
    if (width <= 0) {
4151
4545
        width = 1;
4152
4546
    }
 
4547
 
 
4548
    /*
 
4549
     * Account for window max/min width
 
4550
     */
 
4551
 
 
4552
    if (wmPtr->gridWin != NULL) {
 
4553
        min = winPtr->reqWidth
 
4554
                + (wmPtr->minWidth - wmPtr->reqGridWidth)*wmPtr->widthInc;
 
4555
        if (wmPtr->maxWidth > 0) {
 
4556
            max = winPtr->reqWidth
 
4557
                + (wmPtr->maxWidth - wmPtr->reqGridWidth)*wmPtr->widthInc;
 
4558
        } else {
 
4559
            max = 0;
 
4560
        }
 
4561
    } else {
 
4562
        min = wmPtr->minWidth;
 
4563
        max = wmPtr->maxWidth;
 
4564
    }
 
4565
    if (width < min) {
 
4566
        width = min;
 
4567
    } else if ((max > 0) && (width > max)) {
 
4568
        width = max;
 
4569
    }
 
4570
 
4153
4571
    if (wmPtr->height == -1) {
4154
4572
        height = winPtr->reqHeight;
4155
4573
    } else if (wmPtr->gridWin != NULL) {
4163
4581
    }
4164
4582
 
4165
4583
    /*
 
4584
     * Account for window max/min height
 
4585
     */
 
4586
 
 
4587
    if (wmPtr->gridWin != NULL) {
 
4588
        min = winPtr->reqHeight
 
4589
                + (wmPtr->minHeight - wmPtr->reqGridHeight)*wmPtr->heightInc;
 
4590
        if (wmPtr->maxHeight > 0) {
 
4591
            max = winPtr->reqHeight
 
4592
                + (wmPtr->maxHeight - wmPtr->reqGridHeight)*wmPtr->heightInc;
 
4593
        } else {
 
4594
            max = 0;
 
4595
        }
 
4596
    } else {
 
4597
        min = wmPtr->minHeight;
 
4598
        max = wmPtr->maxHeight;
 
4599
    }
 
4600
    if (height < min) {
 
4601
        height = min;
 
4602
    } else if ((max > 0) && (height > max)) {
 
4603
        height = max;
 
4604
    }
 
4605
 
 
4606
    /*
4166
4607
     * Compute the new position for the upper-left pixel of the window's
4167
 
     * decorative frame.  This is tricky, because we need to include the
4168
 
     * border widths supplied by a reparented parent in this calculation,
4169
 
     * but can't use the parent's current overall size since that may
4170
 
     * change as a result of this code.
 
4608
     * decorative frame. This is tricky, because we need to include the border
 
4609
     * widths supplied by a reparented parent in this calculation, but can't
 
4610
     * use the parent's current overall size since that may change as a result
 
4611
     * of this code.
4171
4612
     */
4172
4613
 
4173
4614
    if (wmPtr->flags & WM_NEGATIVE_X) {
4174
4615
        x = wmPtr->vRootWidth - wmPtr->x
4175
4616
                - (width + (wmPtr->parentWidth - winPtr->changes.width));
4176
4617
    } else {
4177
 
        x =  wmPtr->x;
 
4618
        x = wmPtr->x;
4178
4619
    }
4179
4620
    if (wmPtr->flags & WM_NEGATIVE_Y) {
4180
4621
        y = wmPtr->vRootHeight - wmPtr->y
4181
4622
                - (height + (wmPtr->parentHeight - winPtr->changes.height));
4182
4623
    } else {
4183
 
        y =  wmPtr->y;
 
4624
        y = wmPtr->y;
4184
4625
    }
4185
4626
 
4186
4627
    /*
4187
 
     * If the window's size is going to change and the window is
4188
 
     * supposed to not be resizable by the user, then we have to
4189
 
     * update the size hints.  There may also be a size-hint-update
4190
 
     * request pending from somewhere else, too.
 
4628
     * If the window's size is going to change and the window is supposed to
 
4629
     * not be resizable by the user, then we have to update the size hints.
 
4630
     * There may also be a size-hint-update request pending from somewhere
 
4631
     * else, too.
4191
4632
     */
4192
4633
 
4193
4634
    if (((width != winPtr->changes.width)
4197
4638
        wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
4198
4639
    }
4199
4640
    if (wmPtr->flags & WM_UPDATE_SIZE_HINTS) {
4200
 
        UpdateSizeHints(winPtr);
 
4641
        UpdateSizeHints(winPtr, width, height);
4201
4642
    }
4202
4643
 
4203
4644
    /*
4204
 
     * Reconfigure the wrapper if it isn't already configured correctly.
4205
 
     * A few tricky points:
 
4645
     * Reconfigure the wrapper if it isn't already configured correctly. A few
 
4646
     * tricky points:
4206
4647
     *
4207
 
     * 1. If the window is embeddedand the container is also in this
4208
 
     *    process, don't actually reconfigure the window; just pass the
4209
 
     *    desired size on to the container.  Also, zero out any position
4210
 
     *    information, since embedded windows are not allowed to move.
4211
 
     * 2. Sometimes the window manager will give us a different size
4212
 
     *    than we asked for (e.g. mwm has a minimum size for windows), so
4213
 
     *    base the size check on what we *asked for* last time, not what we
4214
 
     *    got.
 
4648
     * 1. If the window is embeddedand the container is also in this process,
 
4649
     *    don't actually reconfigure the window; just pass the desired size on
 
4650
     *    to the container. Also, zero out any position information, since
 
4651
     *    embedded windows are not allowed to move.
 
4652
     * 2. Sometimes the window manager will give us a different size than we
 
4653
     *    asked for (e.g. mwm has a minimum size for windows), so base the
 
4654
     *    size check on what we *asked for* last time, not what we got.
4215
4655
     * 3. Can't just reconfigure always, because we may not get a
4216
4656
     *    ConfigureNotify event back if nothing changed, so
4217
4657
     *    WaitForConfigureNotify will hang a long time.
4218
 
     * 4. Don't move window unless a new position has been requested for
4219
 
     *    it.  This is because of "features" in some window managers (e.g.
4220
 
     *    twm, as of 4/24/91) where they don't interpret coordinates
4221
 
     *    according to ICCCM.  Moving a window to its current location may
4222
 
     *    cause it to shift position on the screen.
 
4658
     * 4. Don't move window unless a new position has been requested for it.
 
4659
     *    This is because of "features" in some window managers (e.g. twm, as
 
4660
     *    of 4/24/91) where they don't interpret coordinates according to
 
4661
     *    ICCCM. Moving a window to its current location may cause it to shift
 
4662
     *    position on the screen.
4223
4663
     */
4224
4664
 
4225
4665
    if ((winPtr->flags & (TK_EMBEDDED|TK_BOTH_HALVES))
4226
4666
            == (TK_EMBEDDED|TK_BOTH_HALVES)) {
 
4667
        TkWindow *childPtr = TkpGetOtherWindow(winPtr);
 
4668
 
4227
4669
        /*
4228
 
         * This window is embedded and the container is also in this
4229
 
         * process, so we don't need to do anything special about the
4230
 
         * geometry, except to make sure that the desired size is known
4231
 
         * by the container.  Also, zero out any position information,
4232
 
         * since embedded windows are not allowed to move.
 
4670
         * This window is embedded and the container is also in this process,
 
4671
         * so we don't need to do anything special about the geometry, except
 
4672
         * to make sure that the desired size is known by the container. Also,
 
4673
         * zero out any position information, since embedded windows are not
 
4674
         * allowed to move.
4233
4675
         */
4234
4676
 
4235
4677
        wmPtr->x = wmPtr->y = 0;
4236
4678
        wmPtr->flags &= ~(WM_NEGATIVE_X|WM_NEGATIVE_Y);
4237
4679
        height += wmPtr->menuHeight;
4238
 
        Tk_GeometryRequest((Tk_Window) TkpGetOtherWindow(winPtr),
4239
 
                width, height);
 
4680
        if (childPtr != NULL) {
 
4681
            Tk_GeometryRequest((Tk_Window) childPtr, width, height);
 
4682
        }
4240
4683
        return;
4241
4684
    }
4242
4685
    serial = NextRequest(winPtr->display);
4247
4690
                && (width == wmPtr->wrapperPtr->changes.width)
4248
4691
                && (height == wmPtr->wrapperPtr->changes.height)) {
4249
4692
            /*
4250
 
             * The window already has the correct geometry, so don't bother
4251
 
             * to configure it;  the X server appears to ignore these
4252
 
             * requests, so we won't get back a ConfigureNotify and the
 
4693
             * The window already has the correct geometry, so don't bother to
 
4694
             * configure it; the X server appears to ignore these requests, so
 
4695
             * we won't get back a ConfigureNotify and the
4253
4696
             * WaitForConfigureNotify call below will hang for a while.
4254
4697
             */
4255
4698
 
4259
4702
        wmPtr->configWidth = width;
4260
4703
        wmPtr->configHeight = height;
4261
4704
        if (winPtr->dispPtr->flags & TK_DISPLAY_WM_TRACING) {
4262
 
           printf("UpdateGeometryInfo moving to %d %d, resizing to %d x %d,\n",
4263
 
                   x, y, width, height);
 
4705
            printf("UpdateGeometryInfo moving to %d %d, resizing to %dx%d,\n",
 
4706
                    x, y, width, height);
4264
4707
        }
4265
4708
        XMoveResizeWindow(winPtr->display, wmPtr->wrapperPtr->window, x, y,
4266
4709
                (unsigned) width, (unsigned) height);
4269
4712
        if ((width == wmPtr->wrapperPtr->changes.width)
4270
4713
                && (height == wmPtr->wrapperPtr->changes.height)) {
4271
4714
            /*
4272
 
             * The window is already just the size we want, so don't bother
4273
 
             * to configure it;  the X server appears to ignore these
4274
 
             * requests, so we won't get back a ConfigureNotify and the
 
4715
             * The window is already just the size we want, so don't bother to
 
4716
             * configure it; the X server appears to ignore these requests, so
 
4717
             * we won't get back a ConfigureNotify and the
4275
4718
             * WaitForConfigureNotify call below will hang for a while.
4276
4719
             */
4277
4720
 
4289
4732
            && ((Tk_Width(wmPtr->menubar) != wmPtr->wrapperPtr->changes.width)
4290
4733
            || (Tk_Height(wmPtr->menubar) != wmPtr->menuHeight))) {
4291
4734
        /*
4292
 
         * It is possible that the window's overall size has not changed
4293
 
         * but the menu size has.
 
4735
         * It is possible that the window's overall size has not changed but
 
4736
         * the menu size has.
4294
4737
         */
4295
4738
 
4296
4739
        Tk_MoveResizeWindow(wmPtr->menubar, 0, 0,
4302
4745
    }
4303
4746
 
4304
4747
    /*
4305
 
     * Wait for the configure operation to complete.  Don't need to do
4306
 
     * this, however, if the window is about to be mapped:  it will be
4307
 
     * taken care of elsewhere.
 
4748
     * Wait for the configure operation to complete. Don't need to do this,
 
4749
     * however, if the window is about to be mapped: it will be taken care of
 
4750
     * elsewhere.
4308
4751
     */
4309
4752
 
4310
4753
    if (!(wmPtr->flags & WM_ABOUT_TO_MAP)) {
4317
4760
 *
4318
4761
 * UpdateSizeHints --
4319
4762
 *
4320
 
 *      This procedure is called to update the window manager's
4321
 
 *      size hints information from the information in a WmInfo
4322
 
 *      structure.
 
4763
 *      This function is called to update the window manager's size hints
 
4764
 *      information from the information in a WmInfo structure.
4323
4765
 *
4324
4766
 * Results:
4325
4767
 *      None.
4331
4773
 */
4332
4774
 
4333
4775
static void
4334
 
UpdateSizeHints(winPtr)
4335
 
    TkWindow *winPtr;
 
4776
UpdateSizeHints(
 
4777
    TkWindow *winPtr,
 
4778
    int newWidth,
 
4779
    int newHeight)
4336
4780
{
4337
4781
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
4338
4782
    XSizeHints *hintsPtr;
4346
4790
    }
4347
4791
 
4348
4792
    /*
4349
 
     * Compute the pixel-based sizes for the various fields in the
4350
 
     * size hints structure, based on the grid-based sizes in
4351
 
     * our structure.
 
4793
     * Compute the pixel-based sizes for the various fields in the size hints
 
4794
     * structure, based on the grid-based sizes in our structure.
4352
4795
     */
4353
4796
 
4354
4797
    GetMaxSize(wmPtr, &maxWidth, &maxHeight);
4389
4832
    hintsPtr->flags = wmPtr->sizeHintsFlags | PMinSize;
4390
4833
 
4391
4834
    /*
4392
 
     * If the window isn't supposed to be resizable, then set the
4393
 
     * minimum and maximum dimensions to be the same.
 
4835
     * If the window isn't supposed to be resizable, then set the minimum and
 
4836
     * maximum dimensions to be the same.
4394
4837
     */
4395
4838
 
4396
4839
    if (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) {
4397
 
        if (wmPtr->width >= 0) {
4398
 
            hintsPtr->min_width = wmPtr->width;
4399
 
        } else {
4400
 
            hintsPtr->min_width = winPtr->reqWidth;
4401
 
        }
4402
 
        hintsPtr->max_width = hintsPtr->min_width;
 
4840
        hintsPtr->max_width = hintsPtr->min_width = newWidth;
 
4841
        hintsPtr->flags |= PMaxSize;
4403
4842
    }
4404
4843
    if (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) {
4405
 
        if (wmPtr->height >= 0) {
4406
 
            hintsPtr->min_height = wmPtr->height;
4407
 
        } else {
4408
 
            hintsPtr->min_height = winPtr->reqHeight + wmPtr->menuHeight;
4409
 
        }
4410
 
        hintsPtr->max_height = hintsPtr->min_height;
 
4844
        hintsPtr->max_height = hintsPtr->min_height =
 
4845
                newHeight + wmPtr->menuHeight;
 
4846
        hintsPtr->flags |= PMaxSize;
4411
4847
    }
4412
4848
 
4413
4849
    XSetWMNormalHints(winPtr->display, wmPtr->wrapperPtr->window, hintsPtr);
4414
4850
 
4415
4851
    XFree((char *) hintsPtr);
4416
4852
}
 
4853
/*
 
4854
 *--------------------------------------------------------------
 
4855
 *
 
4856
 * UpdateTitle --
 
4857
 *
 
4858
 *      This function is called to update the window title and icon name. It
 
4859
 *      sets the ICCCM-defined properties WM_NAME and WM_ICON_NAME for older
 
4860
 *      window managers, and the freedesktop.org-defined _NET_WM_NAME and
 
4861
 *      _NET_WM_ICON_NAME properties for newer ones. The ICCCM properties are
 
4862
 *      stored in the system encoding, the newer properties are stored in
 
4863
 *      UTF-8.
 
4864
 *
 
4865
 *      NOTE: the ICCCM specifies that WM_NAME and WM_ICON_NAME are stored in
 
4866
 *      ISO-Latin-1. Tk has historically used the default system encoding
 
4867
 *      (since 8.1). It's not clear whether this is correct or not.
 
4868
 *
 
4869
 * Side effects:
 
4870
 *      Properties get changed for winPtr.
 
4871
 *
 
4872
 *--------------------------------------------------------------
 
4873
 */
 
4874
 
 
4875
static void
 
4876
UpdateTitle(
 
4877
    TkWindow *winPtr)
 
4878
{
 
4879
    WmInfo *wmPtr = winPtr->wmInfoPtr;
 
4880
    Atom XA_UTF8_STRING = Tk_InternAtom((Tk_Window) winPtr, "UTF8_STRING");
 
4881
    const char *string;
 
4882
    Tcl_DString ds;
 
4883
 
 
4884
    /*
 
4885
     * Set window title:
 
4886
     */
 
4887
 
 
4888
    string = (wmPtr->title != NULL) ? wmPtr->title : winPtr->nameUid;
 
4889
    Tcl_UtfToExternalDString(NULL, string, -1, &ds);
 
4890
    XStoreName(winPtr->display, wmPtr->wrapperPtr->window,
 
4891
            Tcl_DStringValue(&ds));
 
4892
    Tcl_DStringFree(&ds);
 
4893
 
 
4894
    XChangeProperty(winPtr->display, wmPtr->wrapperPtr->window,
 
4895
            Tk_InternAtom((Tk_Window) winPtr, "_NET_WM_NAME"),
 
4896
            XA_UTF8_STRING, 8, PropModeReplace,
 
4897
            (const unsigned char*)string, (signed int)strlen(string));
 
4898
 
 
4899
    /*
 
4900
     * Set icon name:
 
4901
     */
 
4902
 
 
4903
    if (wmPtr->iconName != NULL) {
 
4904
        Tcl_UtfToExternalDString(NULL, wmPtr->iconName, -1, &ds);
 
4905
        XSetIconName(winPtr->display, wmPtr->wrapperPtr->window,
 
4906
                Tcl_DStringValue(&ds));
 
4907
        Tcl_DStringFree(&ds);
 
4908
 
 
4909
        XChangeProperty(winPtr->display, wmPtr->wrapperPtr->window,
 
4910
                Tk_InternAtom((Tk_Window) winPtr, "_NET_WM_ICON_NAME"),
 
4911
                XA_UTF8_STRING, 8, PropModeReplace,
 
4912
                (const unsigned char*)wmPtr->iconName,
 
4913
                (signed int)strlen(wmPtr->iconName));
 
4914
    }
 
4915
}
 
4916
 
 
4917
/*
 
4918
 *--------------------------------------------------------------
 
4919
 *
 
4920
 * UpdatePhotoIcon --
 
4921
 *
 
4922
 *      This function is called to update the window photo icon. It sets the
 
4923
 *      EWMH-defined properties _NET_WM_ICON.
 
4924
 *
 
4925
 * Side effects:
 
4926
 *      Properties get changed for winPtr.
 
4927
 *
 
4928
 *--------------------------------------------------------------
 
4929
 */
 
4930
 
 
4931
static void
 
4932
UpdatePhotoIcon(
 
4933
    TkWindow *winPtr)
 
4934
{
 
4935
    WmInfo *wmPtr = winPtr->wmInfoPtr;
 
4936
    unsigned char *data = wmPtr->iconDataPtr;
 
4937
    int size = wmPtr->iconDataSize;
 
4938
 
 
4939
    if (data == NULL) {
 
4940
        data = winPtr->dispPtr->iconDataPtr;
 
4941
        size = winPtr->dispPtr->iconDataSize;
 
4942
    }
 
4943
    if (data != NULL) {
 
4944
        /*
 
4945
         * Set icon:
 
4946
         */
 
4947
 
 
4948
        XChangeProperty(winPtr->display, wmPtr->wrapperPtr->window,
 
4949
                Tk_InternAtom((Tk_Window) winPtr, "_NET_WM_ICON"),
 
4950
                XA_CARDINAL, 32, PropModeReplace,
 
4951
                (unsigned char *) data, size);
 
4952
    }
 
4953
}
 
4954
 
 
4955
/*
 
4956
 *----------------------------------------------------------------------
 
4957
 *
 
4958
 * SetNetWmState --
 
4959
 *
 
4960
 *      Sets the specified state property by sending a _NET_WM_STATE
 
4961
 *      ClientMessage to the root window.
 
4962
 *
 
4963
 * Preconditions: 
 
4964
 *
 
4965
 *      Wrapper window must be created.
 
4966
 *
 
4967
 * See also:
 
4968
 *      UpdateNetWmState; EWMH spec, section _NET_WM_STATE.
 
4969
 *
 
4970
 *----------------------------------------------------------------------
 
4971
 */
 
4972
 
 
4973
#define _NET_WM_STATE_REMOVE    0l
 
4974
#define _NET_WM_STATE_ADD       1l
 
4975
#define _NET_WM_STATE_TOGGLE    2l
 
4976
 
 
4977
static void SetNetWmState(TkWindow *winPtr, const char *atomName, int on)
 
4978
{
 
4979
    Tk_Window tkwin = (Tk_Window)winPtr;
 
4980
    Atom messageType = Tk_InternAtom(tkwin, "_NET_WM_STATE");
 
4981
    Atom action = on ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
 
4982
    Atom property = Tk_InternAtom(tkwin, atomName);
 
4983
    XEvent e;
 
4984
 
 
4985
    if (!winPtr->wmInfoPtr->wrapperPtr) {
 
4986
        return;
 
4987
    }
 
4988
 
 
4989
    e.xany.type = ClientMessage;
 
4990
    e.xany.window = winPtr->wmInfoPtr->wrapperPtr->window;
 
4991
    e.xclient.message_type = messageType;
 
4992
    e.xclient.format = 32;
 
4993
    e.xclient.data.l[0] = action;
 
4994
    e.xclient.data.l[1] = property;
 
4995
    e.xclient.data.l[2] = e.xclient.data.l[3] = e.xclient.data.l[4] = 0l;
 
4996
 
 
4997
    XSendEvent(winPtr->display,
 
4998
        RootWindow(winPtr->display, winPtr->screenNum), 0,
 
4999
        SubstructureNotifyMask|SubstructureRedirectMask, &e);
 
5000
}
 
5001
 
 
5002
/*
 
5003
 * CheckNetWmState --
 
5004
 *
 
5005
 *      Updates the window attributes whenever the _NET_WM_STATE
 
5006
 *      property changes.
 
5007
 *
 
5008
 * Notes:
 
5009
 *      
 
5010
 *      Tk uses a single -zoomed state, while the EWMH spec supports 
 
5011
 *      separate vertical and horizontal maximization.  We consider
 
5012
 *      the window to be "zoomed" if _NET_WM_STATE_MAXIMIZED_VERT 
 
5013
 *      and _NET_WM_STATE_MAXIMIZED_HORZ are both set.
 
5014
 */
 
5015
static void CheckNetWmState(WmInfo *wmPtr, Atom *atoms, int numAtoms)
 
5016
{
 
5017
    Tk_Window tkwin = (Tk_Window)wmPtr->wrapperPtr;
 
5018
    int i;
 
5019
    Atom _NET_WM_STATE_ABOVE
 
5020
            = Tk_InternAtom(tkwin, "_NET_WM_STATE_ABOVE"),
 
5021
        _NET_WM_STATE_MAXIMIZED_VERT 
 
5022
            = Tk_InternAtom(tkwin, "_NET_WM_STATE_MAXIMIZED_VERT"),
 
5023
        _NET_WM_STATE_MAXIMIZED_HORZ 
 
5024
            = Tk_InternAtom(tkwin, "_NET_WM_STATE_MAXIMIZED_HORZ"),
 
5025
        _NET_WM_STATE_FULLSCREEN 
 
5026
            = Tk_InternAtom(tkwin, "_NET_WM_STATE_FULLSCREEN");
 
5027
 
 
5028
    wmPtr->attributes.topmost = 0;
 
5029
    wmPtr->attributes.zoomed = 0;
 
5030
    wmPtr->attributes.fullscreen = 0;
 
5031
    for (i = 0; i < numAtoms; ++i) {
 
5032
        if (atoms[i] == _NET_WM_STATE_ABOVE) {
 
5033
            wmPtr->attributes.topmost = 1;
 
5034
        } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT) {
 
5035
            wmPtr->attributes.zoomed |= 1;
 
5036
        } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) {
 
5037
            wmPtr->attributes.zoomed |= 2;
 
5038
        } else if (atoms[i] == _NET_WM_STATE_FULLSCREEN) {
 
5039
            wmPtr->attributes.fullscreen = 1;
 
5040
        }
 
5041
    }
 
5042
 
 
5043
    wmPtr->attributes.zoomed = (wmPtr->attributes.zoomed == 3);
 
5044
 
 
5045
    return;
 
5046
}
 
5047
 
 
5048
/*
 
5049
 * UpdateNetWmState --
 
5050
 *
 
5051
 *      Sets the _NET_WM_STATE property to match the requested attribute state
 
5052
 *      just prior to mapping a withdrawn window.
 
5053
 */
 
5054
#define NET_WM_STATE_MAX_ATOMS 4
 
5055
static void UpdateNetWmState(WmInfo *wmPtr)
 
5056
{
 
5057
    Tk_Window tkwin = (Tk_Window)wmPtr->wrapperPtr;
 
5058
    Atom atoms[NET_WM_STATE_MAX_ATOMS];
 
5059
    long numAtoms = 0;
 
5060
 
 
5061
    if (wmPtr->reqState.topmost) {
 
5062
        atoms[numAtoms++] = Tk_InternAtom(tkwin,"_NET_WM_STATE_ABOVE");
 
5063
    }
 
5064
    if (wmPtr->reqState.zoomed) {
 
5065
        atoms[numAtoms++] = Tk_InternAtom(tkwin,"_NET_WM_STATE_MAXIMIZED_VERT");
 
5066
        atoms[numAtoms++] = Tk_InternAtom(tkwin,"_NET_WM_STATE_MAXIMIZED_HORZ");
 
5067
    } 
 
5068
    if (wmPtr->reqState.fullscreen) {
 
5069
        atoms[numAtoms++] = Tk_InternAtom(tkwin, "_NET_WM_STATE_FULLSCREEN");
 
5070
    }
 
5071
 
 
5072
    XChangeProperty(Tk_Display(tkwin), wmPtr->wrapperPtr->window, 
 
5073
            Tk_InternAtom(tkwin, "_NET_WM_STATE"), XA_ATOM, 32, 
 
5074
            PropModeReplace, (unsigned char *)atoms, numAtoms);
 
5075
}
4417
5076
 
4418
5077
/*
4419
5078
 *----------------------------------------------------------------------
4420
5079
 *
4421
5080
 * WaitForConfigureNotify --
4422
5081
 *
4423
 
 *      This procedure is invoked in order to synchronize with the
4424
 
 *      window manager.  It waits for a ConfigureNotify event to
4425
 
 *      arrive, signalling that the window manager has seen an attempt
4426
 
 *      on our part to move or resize a top-level window.
 
5082
 *      This function is invoked in order to synchronize with the window
 
5083
 *      manager. It waits for a ConfigureNotify event to arrive, signalling
 
5084
 *      that the window manager has seen an attempt on our part to move or
 
5085
 *      resize a top-level window.
4427
5086
 *
4428
5087
 * Results:
4429
5088
 *      None.
4430
5089
 *
4431
5090
 * Side effects:
4432
5091
 *      Delays the execution of the process until a ConfigureNotify event
4433
 
 *      arrives with serial number at least as great as serial.  This
4434
 
 *      is useful for two reasons:
 
5092
 *      arrives with serial number at least as great as serial. This is useful
 
5093
 *      for two reasons:
4435
5094
 *
4436
5095
 *      1. It's important to distinguish ConfigureNotify events that are
4437
5096
 *         coming in response to a request we've made from those generated
4438
 
 *         spontaneously by the user.  The reason for this is that if the
4439
 
 *         user resizes the window we take that as an order to ignore
4440
 
 *         geometry requests coming from inside the window hierarchy.  If
4441
 
 *         we accidentally interpret a response to our request as a
4442
 
 *         user-initiated action, the window will stop responding to
4443
 
 *         new geometry requests.  To make this distinction, (a) this
4444
 
 *         procedure sets a flag for TopLevelEventProc to indicate that
4445
 
 *         we're waiting to sync with the wm, and (b) all changes to
4446
 
 *         the size of a top-level window are followed by calls to this
4447
 
 *         procedure.
4448
 
 *      2. Races and confusion can come about if there are multiple
4449
 
 *         operations outstanding at a time (e.g. two different resizes
4450
 
 *         of the top-level window:  it's hard to tell which of the
4451
 
 *         ConfigureNotify events coming back is for which request).
 
5097
 *         spontaneously by the user. The reason for this is that if the user
 
5098
 *         resizes the window we take that as an order to ignore geometry
 
5099
 *         requests coming from inside the window hierarchy. If we
 
5100
 *         accidentally interpret a response to our request as a
 
5101
 *         user-initiated action, the window will stop responding to new
 
5102
 *         geometry requests. To make this distinction, (a) this function sets
 
5103
 *         a flag for TopLevelEventProc to indicate that we're waiting to sync
 
5104
 *         with the wm, and (b) all changes to the size of a top-level window
 
5105
 *         are followed by calls to this function.
 
5106
 *      2. Races and confusion can come about if there are multiple operations
 
5107
 *         outstanding at a time (e.g. two different resizes of the top-level
 
5108
 *         window: it's hard to tell which of the ConfigureNotify events
 
5109
 *         coming back is for which request).
4452
5110
 *      While waiting, some events covered by StructureNotifyMask are
4453
 
 *      processed (ConfigureNotify, MapNotify, and UnmapNotify)
4454
 
 *      and all others are deferred.
 
5111
 *      processed (ConfigureNotify, MapNotify, and UnmapNotify) and all others
 
5112
 *      are deferred.
4455
5113
 *
4456
5114
 *----------------------------------------------------------------------
4457
5115
 */
4458
5116
 
4459
5117
static void
4460
 
WaitForConfigureNotify(winPtr, serial)
4461
 
    TkWindow *winPtr;           /* Top-level window for which we want
4462
 
                                 * to see a ConfigureNotify. */
4463
 
    unsigned long serial;       /* Serial number of resize request.  Want to
4464
 
                                 * be sure wm has seen this. */
 
5118
WaitForConfigureNotify(
 
5119
    TkWindow *winPtr,           /* Top-level window for which we want to see a
 
5120
                                 * ConfigureNotify. */
 
5121
    unsigned long serial)       /* Serial number of resize request. Want to be
 
5122
                                 * sure wm has seen this. */
4465
5123
{
4466
5124
    WmInfo *wmPtr = winPtr->wmInfoPtr;
4467
5125
    XEvent event;
4470
5128
    Window window = (wmPtr->reparent != None) ? wmPtr->reparent : wmPtr->wrapperPtr->window;
4471
5129
 
4472
5130
    /*
4473
 
     * One more tricky detail about this procedure.  In some cases the
4474
 
     * window manager will decide to ignore a configure request (e.g.
4475
 
     * because it thinks the window is already in the right place).
4476
 
     * To avoid hanging in this situation, only wait for a few seconds,
4477
 
     * then give up.
 
5131
     * One more tricky detail about this function. In some cases the window
 
5132
     * manager will decide to ignore a configure request (e.g. because it
 
5133
     * thinks the window is already in the right place). To avoid hanging in
 
5134
     * this situation, only wait for a few seconds, then give up.
4478
5135
     */
4479
5136
 
4480
5137
    /*
4541
5198
 *
4542
5199
 * WaitForEvent --
4543
5200
 *
4544
 
 *      This procedure is used by WaitForConfigureNotify and
4545
 
 *      WaitForMapNotify to wait for an event of a certain type
4546
 
 *      to arrive.
 
5201
 *      This function is used by WaitForConfigureNotify and WaitForMapNotify
 
5202
 *      to wait for an event of a certain type to arrive.
4547
5203
 *
4548
5204
 * Results:
4549
 
 *      Under normal conditions, TCL_OK is returned and an event for
4550
 
 *      display and window that matches "mask" is stored in *eventPtr.
4551
 
 *      This event  has already been processed by Tk before this procedure
4552
 
 *      returns.  If a long time goes by with no event of the right type
4553
 
 *      arriving, or if an error occurs while waiting for the event to
4554
 
 *      arrive, then TCL_ERROR is returned.
 
5205
 *      Under normal conditions, TCL_OK is returned and an event for display
 
5206
 *      and window that matches "mask" is stored in *eventPtr. This event has
 
5207
 *      already been processed by Tk before this function returns. If a long
 
5208
 *      time goes by with no event of the right type arriving, or if an error
 
5209
 *      occurs while waiting for the event to arrive, then TCL_ERROR is
 
5210
 *      returned.
4555
5211
 *
4556
5212
 * Side effects:
4557
5213
 *      While waiting for the desired event to occur, Configurenotify,
4558
 
 *      MapNotify, and UnmapNotify events for window are processed,
4559
 
 *      as are all ReparentNotify events.
 
5214
 *      MapNotify, and UnmapNotify events for window are processed, as are all
 
5215
 *      ReparentNotify events.
4560
5216
 *
4561
5217
 *----------------------------------------------------------------------
4562
5218
 */
4563
5219
 
4564
5220
static int
4565
 
WaitForEvent(display, wmInfoPtr, type, eventPtr)
4566
 
    Display *display;           /* Display event is coming from. */
4567
 
    WmInfo *wmInfoPtr;          /* Window for which event is desired. */
4568
 
    int type;                   /* Type of event that is wanted. */
4569
 
    XEvent *eventPtr;           /* Place to store event. */
 
5221
WaitForEvent(
 
5222
    Display *display,           /* Display event is coming from. */
 
5223
    WmInfo *wmInfoPtr,          /* Window for which event is desired. */
 
5224
    int type,                   /* Type of event that is wanted. */
 
5225
    XEvent *eventPtr)           /* Place to store event. */
4570
5226
{
4571
5227
    WaitRestrictInfo info;
4572
5228
    Tk_RestrictProc *oldRestrictProc;
4574
5230
    Tcl_Time timeout;
4575
5231
 
4576
5232
    /*
4577
 
     * Set up an event filter to select just the events we want, and
4578
 
     * a timer handler, then wait for events until we get the event
4579
 
     * we want or a timeout happens.
 
5233
     * Set up an event filter to select just the events we want, and a timer
 
5234
     * handler, then wait for events until we get the event we want or a
 
5235
     * timeout happens.
4580
5236
     */
4581
5237
 
4582
5238
    info.display = display;
4608
5264
 *
4609
5265
 * WaitRestrictProc --
4610
5266
 *
4611
 
 *      This procedure is a Tk_RestrictProc that is used to filter
4612
 
 *      events while WaitForEvent is active.
 
5267
 *      This function is a Tk_RestrictProc that is used to filter events while
 
5268
 *      WaitForEvent is active.
4613
5269
 *
4614
5270
 * Results:
4615
 
 *      Returns TK_PROCESS_EVENT if the right event is found.  Also
4616
 
 *      returns TK_PROCESS_EVENT if any ReparentNotify event is found
4617
 
 *      or if the event is a ConfigureNotify, MapNotify, or UnmapNotify
4618
 
 *      for window.  Otherwise returns TK_DEFER_EVENT.
 
5271
 *      Returns TK_PROCESS_EVENT if the right event is found. Also returns
 
5272
 *      TK_PROCESS_EVENT if any ReparentNotify event is found or if the event
 
5273
 *      is a ConfigureNotify, MapNotify, or UnmapNotify for window. Otherwise
 
5274
 *      returns TK_DEFER_EVENT.
4619
5275
 *
4620
5276
 * Side effects:
4621
 
 *      An event may get stored in the area indicated by the caller
4622
 
 *      of WaitForEvent.
 
5277
 *      An event may get stored in the area indicated by the caller of
 
5278
 *      WaitForEvent.
4623
5279
 *
4624
5280
 *----------------------------------------------------------------------
4625
5281
 */
4626
5282
 
4627
5283
static Tk_RestrictAction
4628
 
WaitRestrictProc(clientData, eventPtr)
4629
 
    ClientData clientData;      /* Pointer to WaitRestrictInfo structure. */
4630
 
    XEvent *eventPtr;           /* Event that is about to be handled. */
 
5284
WaitRestrictProc(
 
5285
    ClientData clientData,      /* Pointer to WaitRestrictInfo structure. */
 
5286
    XEvent *eventPtr)           /* Event that is about to be handled. */
4631
5287
{
4632
5288
    WaitRestrictInfo *infoPtr = (WaitRestrictInfo *) clientData;
4633
5289
 
4647
5303
        infoPtr->foundEvent = 1;
4648
5304
        return TK_PROCESS_EVENT;
4649
5305
    }
4650
 
    if (eventPtr->type == ConfigureNotify
4651
 
           || eventPtr->type == MapNotify
4652
 
           || eventPtr->type == UnmapNotify) {
 
5306
    if (eventPtr->type == ConfigureNotify || eventPtr->type == MapNotify
 
5307
            || eventPtr->type == UnmapNotify) {
4653
5308
        return TK_PROCESS_EVENT;
4654
5309
    }
4655
5310
    return TK_DEFER_EVENT;
4660
5315
 *
4661
5316
 * WaitForMapNotify --
4662
5317
 *
4663
 
 *      This procedure is invoked in order to synchronize with the
4664
 
 *      window manager.  It waits for the window's mapped state to
4665
 
 *      reach the value given by mapped.
 
5318
 *      This function is invoked in order to synchronize with the window
 
5319
 *      manager. It waits for the window's mapped state to reach the value
 
5320
 *      given by mapped.
4666
5321
 *
4667
5322
 * Results:
4668
5323
 *      None.
4669
5324
 *
4670
5325
 * Side effects:
4671
 
 *      Delays the execution of the process until winPtr becomes mapped
4672
 
 *      or unmapped, depending on the "mapped" argument.  This allows us
4673
 
 *      to synchronize with the window manager, and allows us to
4674
 
 *      identify changes in window size that come about when the window
4675
 
 *      manager first starts managing the window (as opposed to those
4676
 
 *      requested interactively by the user later).  See the comments
4677
 
 *      for WaitForConfigureNotify and WM_SYNC_PENDING.  While waiting,
4678
 
 *      some events covered by StructureNotifyMask are processed and all
4679
 
 *      others are deferred.
 
5326
 *      Delays the execution of the process until winPtr becomes mapped or
 
5327
 *      unmapped, depending on the "mapped" argument. This allows us to
 
5328
 *      synchronize with the window manager, and allows us to identify changes
 
5329
 *      in window size that come about when the window manager first starts
 
5330
 *      managing the window (as opposed to those requested interactively by
 
5331
 *      the user later). See the comments for WaitForConfigureNotify and
 
5332
 *      WM_SYNC_PENDING. While waiting, some events covered by
 
5333
 *      StructureNotifyMask are processed and all others are deferred.
4680
5334
 *
4681
5335
 *----------------------------------------------------------------------
4682
5336
 */
4683
5337
 
4684
5338
static void
4685
 
WaitForMapNotify(winPtr, mapped)
4686
 
    TkWindow *winPtr;           /* Top-level window for which we want
4687
 
                                 * to see a particular mapping state. */
4688
 
    int mapped;                 /* If non-zero, wait for window to become
 
5339
WaitForMapNotify(
 
5340
    TkWindow *winPtr,           /* Top-level window for which we want to see a
 
5341
                                 * particular mapping state. */
 
5342
    int mapped)                 /* If non-zero, wait for window to become
4689
5343
                                 * mapped, otherwise wait for it to become
4690
5344
                                 * unmapped. */
4691
5345
{
4707
5361
        wmPtr->flags &= ~WM_SYNC_PENDING;
4708
5362
        if (code != TCL_OK) {
4709
5363
            /*
4710
 
             * There are some bizarre situations in which the window
4711
 
             * manager can't respond or chooses not to (e.g. if we've
4712
 
             * got a grab set it can't respond).  If this happens then
4713
 
             * just quit.
 
5364
             * There are some bizarre situations in which the window manager
 
5365
             * can't respond or chooses not to (e.g. if we've got a grab set
 
5366
             * it can't respond). If this happens then just quit.
4714
5367
             */
4715
5368
 
4716
5369
            if (winPtr->dispPtr->flags & TK_DISPLAY_WM_TRACING) {
4731
5384
 *
4732
5385
 * UpdateHints --
4733
5386
 *
4734
 
 *      This procedure is called to update the window manager's
4735
 
 *      hints information from the information in a WmInfo
4736
 
 *      structure.
 
5387
 *      This function is called to update the window manager's hints
 
5388
 *      information from the information in a WmInfo structure.
4737
5389
 *
4738
5390
 * Results:
4739
5391
 *      None.
4745
5397
 */
4746
5398
 
4747
5399
static void
4748
 
UpdateHints(winPtr)
4749
 
    TkWindow *winPtr;
 
5400
UpdateHints(
 
5401
    TkWindow *winPtr)
4750
5402
{
4751
5403
    WmInfo *wmPtr = winPtr->wmInfoPtr;
4752
5404
 
4761
5413
 *
4762
5414
 * ParseGeometry --
4763
5415
 *
4764
 
 *      This procedure parses a geometry string and updates
4765
 
 *      information used to control the geometry of a top-level
4766
 
 *      window.
 
5416
 *      This function parses a geometry string and updates information used to
 
5417
 *      control the geometry of a top-level window.
4767
5418
 *
4768
5419
 * Results:
4769
 
 *      A standard Tcl return value, plus an error message in
4770
 
 *      the interp's result if an error occurs.
 
5420
 *      A standard Tcl return value, plus an error message in the interp's
 
5421
 *      result if an error occurs.
4771
5422
 *
4772
5423
 * Side effects:
4773
5424
 *      The size and/or location of winPtr may change.
4776
5427
 */
4777
5428
 
4778
5429
static int
4779
 
ParseGeometry(interp, string, winPtr)
4780
 
    Tcl_Interp *interp;         /* Used for error reporting. */
4781
 
    char *string;               /* String containing new geometry.  Has the
 
5430
ParseGeometry(
 
5431
    Tcl_Interp *interp,         /* Used for error reporting. */
 
5432
    char *string,               /* String containing new geometry. Has the
4782
5433
                                 * standard form "=wxh+x+y". */
4783
 
    TkWindow *winPtr;           /* Pointer to top-level window whose
4784
 
                                 * geometry is to be changed. */
 
5434
    TkWindow *winPtr)           /* Pointer to top-level window whose geometry
 
5435
                                 * is to be changed. */
4785
5436
{
4786
5437
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
4787
5438
    int x, y, width, height, flags;
4797
5448
    }
4798
5449
 
4799
5450
    /*
4800
 
     * Parse the width and height, if they are present.  Don't
4801
 
     * actually update any of the fields of wmPtr until we've
4802
 
     * successfully parsed the entire geometry string.
 
5451
     * Parse the width and height, if they are present. Don't actually update
 
5452
     * any of the fields of wmPtr until we've successfully parsed the entire
 
5453
     * geometry string.
4803
5454
     */
4804
5455
 
4805
5456
    width = wmPtr->width;
4853
5504
        }
4854
5505
 
4855
5506
        /*
4856
 
         * Assume that the geometry information came from the user,
4857
 
         * unless an explicit source has been specified.  Otherwise
4858
 
         * most window managers assume that the size hints were
4859
 
         * program-specified and they ignore them.
 
5507
         * Assume that the geometry information came from the user, unless an
 
5508
         * explicit source has been specified. Otherwise most window managers
 
5509
         * assume that the size hints were program-specified and they ignore
 
5510
         * them.
4860
5511
         */
4861
5512
 
4862
5513
        if ((wmPtr->sizeHintsFlags & (USPosition|PPosition)) == 0) {
4866
5517
    }
4867
5518
 
4868
5519
    /*
4869
 
     * Everything was parsed OK.  Update the fields of *wmPtr and
4870
 
     * arrange for the appropriate information to be percolated out
4871
 
     * to the window manager at the next idle moment.
 
5520
     * Everything was parsed OK. Update the fields of *wmPtr and arrange for
 
5521
     * the appropriate information to be percolated out to the window manager
 
5522
     * at the next idle moment.
4872
5523
     */
4873
5524
 
4874
5525
    wmPtr->width = width;
4884
5535
    }
4885
5536
    return TCL_OK;
4886
5537
 
4887
 
    error:
4888
 
    Tcl_AppendResult(interp, "bad geometry specifier \"",
4889
 
            string, "\"", (char *) NULL);
 
5538
  error:
 
5539
    Tcl_AppendResult(interp, "bad geometry specifier \"", string, "\"", NULL);
4890
5540
    return TCL_ERROR;
4891
5541
}
4892
5542
 
4895
5545
 *
4896
5546
 * Tk_GetRootCoords --
4897
5547
 *
4898
 
 *      Given a token for a window, this procedure traces through the
4899
 
 *      window's lineage to find the (virtual) root-window coordinates
4900
 
 *      corresponding to point (0,0) in the window.
 
5548
 *      Given a token for a window, this function traces through the window's
 
5549
 *      lineage to find the (virtual) root-window coordinates corresponding to
 
5550
 *      point (0,0) in the window.
4901
5551
 *
4902
5552
 * Results:
4903
 
 *      The locations pointed to by xPtr and yPtr are filled in with
4904
 
 *      the root coordinates of the (0,0) point in tkwin.  If a virtual
4905
 
 *      root window is in effect for the window, then the coordinates
4906
 
 *      in the virtual root are returned.
 
5553
 *      The locations pointed to by xPtr and yPtr are filled in with the root
 
5554
 *      coordinates of the (0,0) point in tkwin. If a virtual root window is
 
5555
 *      in effect for the window, then the coordinates in the virtual root are
 
5556
 *      returned.
4907
5557
 *
4908
5558
 * Side effects:
4909
5559
 *      None.
4912
5562
 */
4913
5563
 
4914
5564
void
4915
 
Tk_GetRootCoords(tkwin, xPtr, yPtr)
4916
 
    Tk_Window tkwin;            /* Token for window. */
4917
 
    int *xPtr;                  /* Where to store x-displacement of (0,0). */
4918
 
    int *yPtr;                  /* Where to store y-displacement of (0,0). */
 
5565
Tk_GetRootCoords(
 
5566
    Tk_Window tkwin,            /* Token for window. */
 
5567
    int *xPtr,                  /* Where to store x-displacement of (0,0). */
 
5568
    int *yPtr)                  /* Where to store y-displacement of (0,0). */
4919
5569
{
4920
5570
    int x, y;
4921
5571
    register TkWindow *winPtr = (TkWindow *) tkwin;
4922
5572
 
4923
5573
    /*
4924
 
     * Search back through this window's parents all the way to a
4925
 
     * top-level window, combining the offsets of each window within
4926
 
     * its parent.
 
5574
     * Search back through this window's parents all the way to a top-level
 
5575
     * window, combining the offsets of each window within its parent.
4927
5576
     */
4928
5577
 
4929
5578
    x = y = 0;
4933
5582
        if ((winPtr->wmInfoPtr != NULL)
4934
5583
                && (winPtr->wmInfoPtr->menubar == (Tk_Window) winPtr)) {
4935
5584
            /*
4936
 
             * This window is a special menubar; switch over to its
4937
 
             * associated toplevel, compensate for their differences in
4938
 
             * y coordinates, then continue with the toplevel (in case
4939
 
             * it's embedded).
 
5585
             * This window is a special menubar; switch over to its associated
 
5586
             * toplevel, compensate for their differences in y coordinates,
 
5587
             * then continue with the toplevel (in case it's embedded).
4940
5588
             */
4941
5589
            y -= winPtr->wmInfoPtr->menuHeight;
4942
5590
            winPtr = winPtr->wmInfoPtr->winPtr;
4950
5598
            otherPtr = TkpGetOtherWindow(winPtr);
4951
5599
            if (otherPtr == NULL) {
4952
5600
                /*
4953
 
                 * The container window is not in the same application.
4954
 
                 * Query the X server.
 
5601
                 * The container window is not in the same application. Query
 
5602
                 * the X server.
4955
5603
                 */
4956
5604
 
4957
5605
                Window root, dummyChild;
4962
5610
                    root = RootWindowOfScreen(Tk_Screen((Tk_Window)winPtr));
4963
5611
                }
4964
5612
                XTranslateCoordinates(winPtr->display, winPtr->window,
4965
 
                    root, 0, 0, &rootX, &rootY, &dummyChild);
 
5613
                        root, 0, 0, &rootX, &rootY, &dummyChild);
4966
5614
                x += rootX;
4967
5615
                y += rootY;
4968
5616
                break;
4969
5617
            } else {
4970
5618
                /*
4971
 
                 * The container window is in the same application.
4972
 
                 * Let's query its coordinates.
 
5619
                 * The container window is in the same application. Let's
 
5620
                 * query its coordinates.
4973
5621
                 */
4974
5622
 
4975
5623
                winPtr = otherPtr;
4990
5638
 *
4991
5639
 * Tk_CoordsToWindow --
4992
5640
 *
4993
 
 *      Given the (virtual) root coordinates of a point, this procedure
4994
 
 *      returns the token for the top-most window covering that point,
4995
 
 *      if there exists such a window in this application.
 
5641
 *      Given the (virtual) root coordinates of a point, this function returns
 
5642
 *      the token for the top-most window covering that point, if there exists
 
5643
 *      such a window in this application.
4996
5644
 *
4997
5645
 * Results:
4998
 
 *      The return result is either a token for the window corresponding
4999
 
 *      to rootX and rootY, or else NULL to indicate that there is no such
 
5646
 *      The return result is either a token for the window corresponding to
 
5647
 *      rootX and rootY, or else NULL to indicate that there is no such
5000
5648
 *      window.
5001
5649
 *
5002
5650
 * Side effects:
5006
5654
 */
5007
5655
 
5008
5656
Tk_Window
5009
 
Tk_CoordsToWindow(rootX, rootY, tkwin)
5010
 
    int rootX, rootY;           /* Coordinates of point in root window.  If
5011
 
                                 * a virtual-root window manager is in use,
 
5657
Tk_CoordsToWindow(
 
5658
    int rootX, int rootY,       /* Coordinates of point in root window. If a
 
5659
                                 * virtual-root window manager is in use,
5012
5660
                                 * these coordinates refer to the virtual
5013
5661
                                 * root, not the real root. */
5014
 
    Tk_Window tkwin;            /* Token for any window in application;
5015
 
                                 * used to identify the display. */
 
5662
    Tk_Window tkwin)            /* Token for any window in application; used
 
5663
                                 * to identify the display. */
5016
5664
{
5017
5665
    Window window, parent, child;
5018
5666
    int x, y, childX, childY, tmpx, tmpy, bd;
5022
5670
    Tk_ErrorHandler handler = NULL;
5023
5671
 
5024
5672
    /*
5025
 
     * Step 1: scan the list of toplevel windows to see if there is a
5026
 
     * virtual root for the screen we're interested in.  If so, we have
5027
 
     * to translate the coordinates from virtual root to root
5028
 
     * coordinates.
 
5673
     * Step 1: scan the list of toplevel windows to see if there is a virtual
 
5674
     * root for the screen we're interested in. If so, we have to translate
 
5675
     * the coordinates from virtual root to root coordinates.
5029
5676
     */
5030
5677
 
5031
5678
    parent = window = RootWindowOfScreen(Tk_Screen(tkwin));
5032
5679
    x = rootX;
5033
5680
    y = rootY;
5034
 
    for (wmPtr = (WmInfo *) dispPtr->firstWmPtr; wmPtr != NULL; wmPtr = wmPtr->nextPtr) {
 
5681
    for (wmPtr = (WmInfo *) dispPtr->firstWmPtr; wmPtr != NULL;
 
5682
            wmPtr = wmPtr->nextPtr) {
5035
5683
        if (Tk_Screen(wmPtr->winPtr) != Tk_Screen(tkwin)) {
5036
5684
            continue;
5037
5685
        }
5044
5692
    }
5045
5693
 
5046
5694
    /*
5047
 
     * Step 2: work down through the window hierarchy starting at the
5048
 
     * root. For each window, find the child that contains the given
5049
 
     * point and then see if this child is either a wrapper for one of
5050
 
     * our toplevel windows or a window manager decoration window for
5051
 
     * one of our toplevels.  This approach handles several tricky
5052
 
     * cases:
 
5695
     * Step 2: work down through the window hierarchy starting at the root.
 
5696
     * For each window, find the child that contains the given point and then
 
5697
     * see if this child is either a wrapper for one of our toplevel windows
 
5698
     * or a window manager decoration window for one of our toplevels. This
 
5699
     * approach handles several tricky cases:
5053
5700
     *
5054
 
     * 1. There may be a virtual root window between the root and one of
5055
 
     *    our toplevels.
 
5701
     * 1. There may be a virtual root window between the root and one of our
 
5702
     *    toplevels.
5056
5703
     * 2. If a toplevel is embedded, we may have to search through the
5057
 
     *    windows of the container application(s) before getting to
5058
 
     *    the toplevel.
 
5704
     *    windows of the container application(s) before getting to the
 
5705
     *    toplevel.
5059
5706
     */
5060
5707
 
5061
 
    handler = Tk_CreateErrorHandler(Tk_Display(tkwin), -1, -1, -1,
5062
 
            (Tk_ErrorProc *) NULL, (ClientData) NULL);
 
5708
    handler = Tk_CreateErrorHandler(Tk_Display(tkwin), -1, -1, -1, NULL, NULL);
5063
5709
    while (1) {
5064
5710
        if (XTranslateCoordinates(Tk_Display(tkwin), parent, window,
5065
5711
                x, y, &childX, &childY, &child) == False) {
5066
5712
            /*
5067
 
             * We can end up here when the window is in the middle of
5068
 
             * being deleted
 
5713
             * We can end up here when the window is in the middle of being
 
5714
             * deleted
5069
5715
             */
 
5716
 
5070
5717
            Tk_DeleteErrorHandler(handler);
5071
5718
            return NULL;
5072
5719
        }
5075
5722
            return NULL;
5076
5723
        }
5077
5724
        for (wmPtr = (WmInfo *) dispPtr->firstWmPtr; wmPtr != NULL;
5078
 
                wmPtr = wmPtr->nextPtr) {
 
5725
                wmPtr = wmPtr->nextPtr) {
5079
5726
            if (wmPtr->reparent == child) {
5080
5727
                goto gotToplevel;
5081
5728
            }
5093
5740
        window = child;
5094
5741
    }
5095
5742
 
5096
 
    gotToplevel:
 
5743
  gotToplevel:
5097
5744
    if (handler) {
5098
5745
        /*
5099
 
         * Check value of handler, because we can reach this label
5100
 
         * from above or below
 
5746
         * Check value of handler, because we can reach this label from above
 
5747
         * or below
5101
5748
         */
 
5749
 
5102
5750
        Tk_DeleteErrorHandler(handler);
5103
5751
        handler = NULL;
5104
5752
    }
5110
5758
    /*
5111
5759
     * Step 3: at this point winPtr and wmPtr refer to the toplevel that
5112
5760
     * contains the given coordinates, and childX and childY give the
5113
 
     * translated coordinates in the *parent* of the toplevel.  Now
5114
 
     * decide whether the coordinates are in the menubar or the actual
5115
 
     * toplevel, and translate the coordinates into the coordinate
5116
 
     * system of that window.
 
5761
     * translated coordinates in the *parent* of the toplevel. Now decide
 
5762
     * whether the coordinates are in the menubar or the actual toplevel, and
 
5763
     * translate the coordinates into the coordinate system of that window.
5117
5764
     */
5118
5765
 
5119
5766
    x = childX - winPtr->changes.x;
5134
5781
    }
5135
5782
 
5136
5783
    /*
5137
 
     * Step 4: work down through the hierarchy underneath the current
5138
 
     * window. At each level, scan through all the children to find the
5139
 
     * highest one in the stacking order that contains the point.  Then
5140
 
     * repeat the whole process on that child.
 
5784
     * Step 4: work down through the hierarchy underneath the current window.
 
5785
     * At each level, scan through all the children to find the highest one in
 
5786
     * the stacking order that contains the point. Then repeat the whole
 
5787
     * process on that child.
5141
5788
     */
5142
5789
 
5143
5790
    while (1) {
5144
5791
        nextPtr = NULL;
5145
5792
        for (childPtr = winPtr->childList; childPtr != NULL;
5146
5793
                childPtr = childPtr->nextPtr) {
5147
 
            if (!Tk_IsMapped(childPtr) || (childPtr->flags & TK_TOP_HIERARCHY)) {
 
5794
            if (!Tk_IsMapped(childPtr)
 
5795
                    || (childPtr->flags & TK_TOP_HIERARCHY)) {
5148
5796
                continue;
5149
5797
            }
5150
5798
            if (childPtr->flags & TK_REPARENTED) {
5169
5817
                && (winPtr->flags & TK_BOTH_HALVES)) {
5170
5818
            /*
5171
5819
             * The window containing the point is a container, and the
5172
 
             * embedded application is in this same process.  Switch
5173
 
             * over to the toplevel for the embedded application and
5174
 
             * start processing that toplevel from scratch.
 
5820
             * embedded application is in this same process. Switch over to
 
5821
             * the toplevel for the embedded application and start processing
 
5822
             * that toplevel from scratch.
5175
5823
             */
5176
5824
 
5177
5825
            winPtr = TkpGetOtherWindow(winPtr);
 
5826
            if (winPtr == NULL) {
 
5827
                return NULL;
 
5828
            }
5178
5829
            wmPtr = winPtr->wmInfoPtr;
5179
5830
            childX = x;
5180
5831
            childY = y;
5189
5840
 *
5190
5841
 * UpdateVRootGeometry --
5191
5842
 *
5192
 
 *      This procedure is called to update all the virtual root
5193
 
 *      geometry information in wmPtr.
 
5843
 *      This function is called to update all the virtual root geometry
 
5844
 *      information in wmPtr.
5194
5845
 *
5195
5846
 * Results:
5196
5847
 *      None.
5197
5848
 *
5198
5849
 * Side effects:
5199
 
 *      The vRootX, vRootY, vRootWidth, and vRootHeight fields in
5200
 
 *      wmPtr are filled with the most up-to-date information.
 
5850
 *      The vRootX, vRootY, vRootWidth, and vRootHeight fields in wmPtr are
 
5851
 *      filled with the most up-to-date information.
5201
5852
 *
5202
5853
 *----------------------------------------------------------------------
5203
5854
 */
5204
5855
 
5205
5856
static void
5206
 
UpdateVRootGeometry(wmPtr)
5207
 
    WmInfo *wmPtr;              /* Window manager information to be
5208
 
                                 * updated.  The wmPtr->vRoot field must
5209
 
                                 * be valid. */
 
5857
UpdateVRootGeometry(
 
5858
    WmInfo *wmPtr)              /* Window manager information to be updated.
 
5859
                                 * The wmPtr->vRoot field must be valid. */
5210
5860
{
5211
5861
    TkWindow *winPtr = wmPtr->winPtr;
5212
5862
    int bd;
5222
5872
 
5223
5873
    wmPtr->flags &= ~WM_VROOT_OFFSET_STALE;
5224
5874
    if (wmPtr->vRoot == None) {
5225
 
        noVRoot:
 
5875
    noVRoot:
5226
5876
        wmPtr->vRootX = wmPtr->vRootY = 0;
5227
5877
        wmPtr->vRootWidth = DisplayWidth(winPtr->display, winPtr->screenNum);
5228
5878
        wmPtr->vRootHeight = DisplayHeight(winPtr->display, winPtr->screenNum);
5233
5883
     * Refresh the virtual root information if it's out of date.
5234
5884
     */
5235
5885
 
5236
 
    handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1,
5237
 
            (Tk_ErrorProc *) NULL, (ClientData) NULL);
 
5886
    handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1, NULL, NULL);
5238
5887
    status = XGetGeometry(winPtr->display, wmPtr->vRoot,
5239
5888
            &dummy2, &wmPtr->vRootX, &wmPtr->vRootY,
5240
5889
            (unsigned int *) &wmPtr->vRootWidth,
5248
5897
    Tk_DeleteErrorHandler(handler);
5249
5898
    if (status == 0) {
5250
5899
        /*
5251
 
         * The virtual root is gone!  Pretend that it never existed.
 
5900
         * The virtual root is gone! Pretend that it never existed.
5252
5901
         */
5253
5902
 
5254
5903
        wmPtr->vRoot = None;
5261
5910
 *
5262
5911
 * Tk_GetVRootGeometry --
5263
5912
 *
5264
 
 *      This procedure returns information about the virtual root
5265
 
 *      window corresponding to a particular Tk window.
 
5913
 *      This function returns information about the virtual root window
 
5914
 *      corresponding to a particular Tk window.
5266
5915
 *
5267
5916
 * Results:
5268
 
 *      The values at xPtr, yPtr, widthPtr, and heightPtr are set
5269
 
 *      with the offset and dimensions of the root window corresponding
5270
 
 *      to tkwin.  If tkwin is being managed by a virtual root window
5271
 
 *      manager these values correspond to the virtual root window being
5272
 
 *      used for tkwin;  otherwise the offsets will be 0 and the
5273
 
 *      dimensions will be those of the screen.
 
5917
 *      The values at xPtr, yPtr, widthPtr, and heightPtr are set with the
 
5918
 *      offset and dimensions of the root window corresponding to tkwin. If
 
5919
 *      tkwin is being managed by a virtual root window manager these values
 
5920
 *      correspond to the virtual root window being used for tkwin; otherwise
 
5921
 *      the offsets will be 0 and the dimensions will be those of the screen.
5274
5922
 *
5275
5923
 * Side effects:
5276
5924
 *      Vroot window information is refreshed if it is out of date.
5279
5927
 */
5280
5928
 
5281
5929
void
5282
 
Tk_GetVRootGeometry(tkwin, xPtr, yPtr, widthPtr, heightPtr)
5283
 
    Tk_Window tkwin;            /* Window whose virtual root is to be
 
5930
Tk_GetVRootGeometry(
 
5931
    Tk_Window tkwin,            /* Window whose virtual root is to be
5284
5932
                                 * queried. */
5285
 
    int *xPtr, *yPtr;           /* Store x and y offsets of virtual root
 
5933
    int *xPtr, int *yPtr,       /* Store x and y offsets of virtual root
5286
5934
                                 * here. */
5287
 
    int *widthPtr, *heightPtr;  /* Store dimensions of virtual root here. */
 
5935
    int *widthPtr, int *heightPtr)
 
5936
                                /* Store dimensions of virtual root here. */
5288
5937
{
5289
5938
    WmInfo *wmPtr;
5290
5939
    TkWindow *winPtr = (TkWindow *) tkwin;
5294
5943
     * information for that window.
5295
5944
     */
5296
5945
 
5297
 
    while (!(winPtr->flags & TK_TOP_HIERARCHY) && (winPtr->parentPtr != NULL)) {
 
5946
    while (!(winPtr->flags & TK_TOP_HIERARCHY)
 
5947
            && (winPtr->parentPtr != NULL)) {
5298
5948
        winPtr = winPtr->parentPtr;
5299
5949
    }
5300
5950
    wmPtr = winPtr->wmInfoPtr;
5306
5956
        *heightPtr = 0;
5307
5957
    }
5308
5958
 
5309
 
 
5310
5959
    /*
5311
 
     * Make sure that the geometry information is up-to-date, then copy
5312
 
     * it out to the caller.
 
5960
     * Make sure that the geometry information is up-to-date, then copy it out
 
5961
     * to the caller.
5313
5962
     */
5314
5963
 
5315
5964
    if (wmPtr->flags & WM_VROOT_OFFSET_STALE) {
5326
5975
 *
5327
5976
 * Tk_MoveToplevelWindow --
5328
5977
 *
5329
 
 *      This procedure is called instead of Tk_MoveWindow to adjust
5330
 
 *      the x-y location of a top-level window.  It delays the actual
5331
 
 *      move to a later time and keeps window-manager information
5332
 
 *      up-to-date with the move
 
5978
 *      This function is called instead of Tk_MoveWindow to adjust the x-y
 
5979
 *      location of a top-level window. It delays the actual move to a later
 
5980
 *      time and keeps window-manager information up-to-date with the move
5333
5981
 *
5334
5982
 * Results:
5335
5983
 *      None.
5336
5984
 *
5337
5985
 * Side effects:
5338
5986
 *      The window is eventually moved so that its upper-left corner
5339
 
 *      (actually, the upper-left corner of the window's decorative
5340
 
 *      frame, if there is one) is at (x,y).
 
5987
 *      (actually, the upper-left corner of the window's decorative frame, if
 
5988
 *      there is one) is at (x,y).
5341
5989
 *
5342
5990
 *----------------------------------------------------------------------
5343
5991
 */
5344
5992
 
5345
5993
void
5346
 
Tk_MoveToplevelWindow(tkwin, x, y)
5347
 
    Tk_Window tkwin;            /* Window to move. */
5348
 
    int x, y;                   /* New location for window (within
5349
 
                                 * parent). */
 
5994
Tk_MoveToplevelWindow(
 
5995
    Tk_Window tkwin,            /* Window to move. */
 
5996
    int x, int y)               /* New location for window (within parent). */
5350
5997
{
5351
5998
    TkWindow *winPtr = (TkWindow *) tkwin;
5352
5999
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
5353
6000
 
5354
6001
    if (!(winPtr->flags & TK_TOP_LEVEL)) {
5355
 
        panic("Tk_MoveToplevelWindow called with non-toplevel window");
 
6002
        Tcl_Panic("Tk_MoveToplevelWindow called with non-toplevel window");
5356
6003
    }
5357
6004
    wmPtr->x = x;
5358
6005
    wmPtr->y = y;
5365
6012
 
5366
6013
    /*
5367
6014
     * If the window has already been mapped, must bring its geometry
5368
 
     * up-to-date immediately, otherwise an event might arrive from the
5369
 
     * server that would overwrite wmPtr->x and wmPtr->y and lose the
5370
 
     * new position.
 
6015
     * up-to-date immediately, otherwise an event might arrive from the server
 
6016
     * that would overwrite wmPtr->x and wmPtr->y and lose the new position.
5371
6017
     */
5372
6018
 
5373
6019
    if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
5383
6029
 *
5384
6030
 * UpdateWmProtocols --
5385
6031
 *
5386
 
 *      This procedure transfers the most up-to-date information about
5387
 
 *      window manager protocols from the WmInfo structure to the actual
5388
 
 *      property on the top-level window.
 
6032
 *      This function transfers the most up-to-date information about window
 
6033
 *      manager protocols from the WmInfo structure to the actual property on
 
6034
 *      the top-level window.
5389
6035
 *
5390
6036
 * Results:
5391
6037
 *      None.
5397
6043
 */
5398
6044
 
5399
6045
static void
5400
 
UpdateWmProtocols(wmPtr)
5401
 
    register WmInfo *wmPtr;     /* Information about top-level window. */
 
6046
UpdateWmProtocols(
 
6047
    register WmInfo *wmPtr)     /* Information about top-level window. */
5402
6048
{
5403
6049
    register ProtocolHandler *protPtr;
5404
6050
    Atom deleteWindowAtom;
5406
6052
    Atom *arrayPtr, *atomPtr;
5407
6053
 
5408
6054
    /*
5409
 
     * There are only two tricky parts here.  First, there could be any
5410
 
     * number of atoms for the window, so count them and malloc an array
5411
 
     * to hold all of their atoms.  Second, we *always* want to respond
5412
 
     * to the WM_DELETE_WINDOW protocol, even if no-one's officially asked.
 
6055
     * There are only two tricky parts here. First, there could be any number
 
6056
     * of atoms for the window, so count them and malloc an array to hold all
 
6057
     * of their atoms. Second, we *always* want to respond to the
 
6058
     * WM_DELETE_WINDOW protocol, even if no-one's officially asked.
5413
6059
     */
5414
6060
 
5415
6061
    for (protPtr = wmPtr->protPtr, count = 1; protPtr != NULL;
5416
6062
            protPtr = protPtr->nextPtr, count++) {
5417
 
        /* Empty loop body;  we're just counting the handlers. */
 
6063
        /* Empty loop body; we're just counting the handlers. */
5418
6064
    }
5419
6065
    arrayPtr = (Atom *) ckalloc((unsigned) (count * sizeof(Atom)));
5420
6066
    deleteWindowAtom = Tk_InternAtom((Tk_Window) wmPtr->winPtr,
5439
6085
 *
5440
6086
 * TkWmProtocolEventProc --
5441
6087
 *
5442
 
 *      This procedure is called by the Tk_HandleEvent whenever a
5443
 
 *      ClientMessage event arrives whose type is "WM_PROTOCOLS".
5444
 
 *      This procedure handles the message from the window manager
5445
 
 *      in an appropriate fashion.
 
6088
 *      This function is called by the Tk_HandleEvent whenever a ClientMessage
 
6089
 *      event arrives whose type is "WM_PROTOCOLS". This function handles the
 
6090
 *      message from the window manager in an appropriate fashion.
5446
6091
 *
5447
6092
 * Results:
5448
6093
 *      None.
5449
6094
 *
5450
6095
 * Side effects:
5451
 
 *      Depends on what sort of handler, if any, was set up for the
5452
 
 *      protocol.
 
6096
 *      Depends on what sort of handler, if any, was set up for the protocol.
5453
6097
 *
5454
6098
 *----------------------------------------------------------------------
5455
6099
 */
5456
6100
 
5457
6101
void
5458
 
TkWmProtocolEventProc(winPtr, eventPtr)
5459
 
    TkWindow *winPtr;           /* Window to which the event was sent. */
5460
 
    XEvent *eventPtr;           /* X event. */
 
6102
TkWmProtocolEventProc(
 
6103
    TkWindow *winPtr,           /* Window to which the event was sent. */
 
6104
    XEvent *eventPtr)           /* X event. */
5461
6105
{
5462
6106
    WmInfo *wmPtr;
5463
6107
    register ProtocolHandler *protPtr;
5473
6117
    protocol = (Atom) eventPtr->xclient.data.l[0];
5474
6118
 
5475
6119
    /*
5476
 
     * Note: it's very important to retrieve the protocol name now,
5477
 
     * before invoking the command, even though the name won't be used
5478
 
     * until after the command returns.  This is because the command
5479
 
     * could delete winPtr, making it impossible for us to use it
5480
 
     * later in the call to Tk_GetAtomName.
 
6120
     * Note: it's very important to retrieve the protocol name now, before
 
6121
     * invoking the command, even though the name won't be used until after
 
6122
     * the command returns. This is because the command could delete winPtr,
 
6123
     * making it impossible for us to use it later in the call to
 
6124
     * Tk_GetAtomName.
5481
6125
     */
5482
6126
 
5483
6127
    protocolName = Tk_GetAtomName((Tk_Window) winPtr, protocol);
5485
6129
            protPtr = protPtr->nextPtr) {
5486
6130
        if (protocol == protPtr->protocol) {
5487
6131
            Tcl_Preserve((ClientData) protPtr);
5488
 
            interp = protPtr->interp;
5489
 
            Tcl_Preserve((ClientData) interp);
 
6132
            interp = protPtr->interp;
 
6133
            Tcl_Preserve((ClientData) interp);
5490
6134
            winPtr->dispPtr->lastEventTime = (Time) eventPtr->xclient.data.l[1];
5491
6135
            result = LangDoCallback(protPtr->interp, protPtr->command, 0, 0);
5492
6136
            if (result != TCL_OK) {
5496
6140
                        "\" window manager protocol)");
5497
6141
                Tcl_BackgroundError(interp);
5498
6142
            }
5499
 
            Tcl_Release((ClientData) interp);
 
6143
            Tcl_Release((ClientData) interp);
5500
6144
            Tcl_Release((ClientData) protPtr);
5501
6145
            return;
5502
6146
        }
5503
6147
    }
5504
6148
 
5505
6149
    /*
5506
 
     * No handler was present for this protocol.  If this is a
5507
 
     * WM_DELETE_WINDOW message then just destroy the window.
 
6150
     * No handler was present for this protocol. If this is a WM_DELETE_WINDOW
 
6151
     * message then just destroy the window.
5508
6152
     */
5509
6153
 
5510
6154
    if (protocol == Tk_InternAtom((Tk_Window) winPtr, "WM_DELETE_WINDOW")) {
5517
6161
 *
5518
6162
 * TkWmStackorderToplevelWrapperMap --
5519
6163
 *
5520
 
 *      This procedure will create a table that maps the reparent wrapper
5521
 
 *      X id for a toplevel to the TkWindow structure that is wraps.
5522
 
 *      Tk keeps track of a mapping from the window X id to the TkWindow
5523
 
 *      structure but that does us no good here since we only get the X
5524
 
 *      id of the wrapper window. Only those toplevel windows that are
5525
 
 *      mapped have a position in the stacking order.
 
6164
 *      This function will create a table that maps the reparent wrapper X id
 
6165
 *      for a toplevel to the TkWindow structure that is wraps. Tk keeps track
 
6166
 *      of a mapping from the window X id to the TkWindow structure but that
 
6167
 *      does us no good here since we only get the X id of the wrapper window.
 
6168
 *      Only those toplevel windows that are mapped have a position in the
 
6169
 *      stacking order.
5526
6170
 *
5527
6171
 * Results:
5528
6172
 *      None.
5534
6178
 */
5535
6179
 
5536
6180
static void
5537
 
TkWmStackorderToplevelWrapperMap(winPtr, table)
5538
 
    TkWindow *winPtr;                           /* TkWindow to recurse on */
5539
 
    Tcl_HashTable *table;                       /* Maps X id to TkWindow */
 
6181
TkWmStackorderToplevelWrapperMap(
 
6182
    TkWindow *winPtr,           /* TkWindow to recurse on */
 
6183
    Display *display,           /* X display of parent window */
 
6184
    Tcl_HashTable *table)       /* Maps X id to TkWindow */
5540
6185
{
5541
6186
    TkWindow *childPtr;
5542
 
    Tcl_HashEntry *hPtr;
5543
 
    Window wrapper;
5544
 
    int newEntry;
5545
6187
 
5546
6188
    if (Tk_IsMapped(winPtr) && Tk_IsTopLevel(winPtr) &&
5547
 
            !Tk_IsEmbedded(winPtr)) {
5548
 
        wrapper = (winPtr->wmInfoPtr->reparent != None)
5549
 
            ? winPtr->wmInfoPtr->reparent
5550
 
            : winPtr->wmInfoPtr->wrapperPtr->window;
 
6189
            !Tk_IsEmbedded(winPtr) && (winPtr->display == display)) {
 
6190
        Window wrapper = (winPtr->wmInfoPtr->reparent != None)
 
6191
                ? winPtr->wmInfoPtr->reparent
 
6192
                : winPtr->wmInfoPtr->wrapperPtr->window;
 
6193
        Tcl_HashEntry *hPtr;
 
6194
        int newEntry;
5551
6195
 
5552
 
        hPtr = Tcl_CreateHashEntry(table,
5553
 
            (char *) wrapper, &newEntry);
5554
 
        Tcl_SetHashValue(hPtr, winPtr);
 
6196
        hPtr = Tcl_CreateHashEntry(table, (char *) wrapper, &newEntry);
 
6197
        Tcl_SetHashValue(hPtr, winPtr);
5555
6198
    }
5556
6199
 
5557
6200
    for (childPtr = winPtr->childList; childPtr != NULL;
5558
 
            childPtr = childPtr->nextPtr) {
5559
 
        TkWmStackorderToplevelWrapperMap(childPtr, table);
 
6201
            childPtr = childPtr->nextPtr) {
 
6202
        TkWmStackorderToplevelWrapperMap(childPtr, display, table);
5560
6203
    }
5561
6204
}
5562
6205
 
5565
6208
 *
5566
6209
 * TkWmStackorderToplevel --
5567
6210
 *
5568
 
 *      This procedure returns the stack order of toplevel windows.
 
6211
 *      This function returns the stack order of toplevel windows.
5569
6212
 *
5570
6213
 * Results:
5571
 
 *      An array of pointers to tk window objects in stacking order
5572
 
 *      or else NULL if there was an error.
 
6214
 *      An array of pointers to tk window objects in stacking order or else
 
6215
 *      NULL if there was an error.
5573
6216
 *
5574
6217
 * Side effects:
5575
6218
 *      None.
5578
6221
 */
5579
6222
 
5580
6223
TkWindow **
5581
 
TkWmStackorderToplevel(parentPtr)
5582
 
    TkWindow *parentPtr;                /* Parent toplevel window. */
 
6224
TkWmStackorderToplevel(
 
6225
    TkWindow *parentPtr)        /* Parent toplevel window. */
5583
6226
{
5584
6227
    Window dummy1, dummy2, vRoot;
5585
6228
    Window *children;
5594
6237
     */
5595
6238
 
5596
6239
    Tcl_InitHashTable(&table, TCL_ONE_WORD_KEYS);
5597
 
    TkWmStackorderToplevelWrapperMap(parentPtr, &table);
 
6240
    TkWmStackorderToplevelWrapperMap(parentPtr, parentPtr->display, &table);
5598
6241
 
5599
 
    window_ptr = windows = (TkWindow **) ckalloc((table.numEntries+1)
5600
 
        * sizeof(TkWindow *));
 
6242
    window_ptr = windows = (TkWindow **)
 
6243
            ckalloc((table.numEntries+1) * sizeof(TkWindow *));
5601
6244
 
5602
6245
    /*
5603
 
     * Special cases: If zero or one toplevels were mapped
5604
 
     * there is no need to call XQueryTree.
 
6246
     * Special cases: If zero or one toplevels were mapped there is no need to
 
6247
     * call XQueryTree.
5605
6248
     */
5606
6249
 
5607
6250
    switch (table.numEntries) {
5608
6251
    case 0:
5609
 
        windows[0] = NULL;
5610
 
        goto done;
 
6252
        windows[0] = NULL;
 
6253
        goto done;
5611
6254
    case 1:
5612
 
        hPtr = Tcl_FirstHashEntry(&table, &search);
5613
 
        windows[0] = (TkWindow *) Tcl_GetHashValue(hPtr);
5614
 
        windows[1] = NULL;
5615
 
        goto done;
 
6255
        hPtr = Tcl_FirstHashEntry(&table, &search);
 
6256
        windows[0] = (TkWindow *) Tcl_GetHashValue(hPtr);
 
6257
        windows[1] = NULL;
 
6258
        goto done;
5616
6259
    }
5617
6260
 
5618
6261
    vRoot = parentPtr->wmInfoPtr->vRoot;
5619
6262
    if (vRoot == None) {
5620
 
        vRoot = RootWindowOfScreen(Tk_Screen((Tk_Window) parentPtr));
 
6263
        vRoot = RootWindowOfScreen(Tk_Screen((Tk_Window) parentPtr));
5621
6264
    }
5622
6265
 
5623
6266
    if (XQueryTree(parentPtr->display, vRoot, &dummy1, &dummy2,
5624
 
            &children, &numChildren) == 0) {
5625
 
        ckfree((char *) windows);
5626
 
        windows = NULL;
 
6267
            &children, &numChildren) == 0) {
 
6268
        ckfree((char *) windows);
 
6269
        windows = NULL;
5627
6270
    } else {
5628
 
        for (i = 0; i < numChildren; i++) {
5629
 
            hPtr = Tcl_FindHashEntry(&table, (char *) children[i]);
5630
 
            if (hPtr != NULL) {
5631
 
                childWinPtr = (TkWindow *) Tcl_GetHashValue(hPtr);
5632
 
                *window_ptr++ = childWinPtr;
5633
 
            }
5634
 
        }
5635
 
        if ((window_ptr - windows) != table.numEntries)
5636
 
            panic("num matched toplevel windows does not equal num children");
5637
 
        *window_ptr = NULL;
 
6271
        for (i = 0; i < numChildren; i++) {
 
6272
            hPtr = Tcl_FindHashEntry(&table, (char *) children[i]);
 
6273
            if (hPtr != NULL) {
 
6274
                childWinPtr = (TkWindow *) Tcl_GetHashValue(hPtr);
 
6275
                *window_ptr++ = childWinPtr;
 
6276
            }
 
6277
        }
 
6278
        if ((window_ptr - windows) != table.numEntries) {
 
6279
            Tcl_Panic("num matched toplevel windows does not equal num children");
 
6280
        }
 
6281
        *window_ptr = NULL;
5638
6282
        if (numChildren) {
5639
6283
            XFree((char *) children);
5640
6284
        }
5641
6285
    }
5642
6286
 
5643
 
    done:
 
6287
  done:
5644
6288
    Tcl_DeleteHashTable(&table);
5645
6289
    return windows;
5646
6290
}
5650
6294
 *
5651
6295
 * TkWmRestackToplevel --
5652
6296
 *
5653
 
 *      This procedure restacks a top-level window.
 
6297
 *      This function restacks a top-level window.
5654
6298
 *
5655
6299
 * Results:
5656
6300
 *      None.
5657
6301
 *
5658
6302
 * Side effects:
5659
 
 *      WinPtr gets restacked  as specified by aboveBelow and otherPtr.
 
6303
 *      WinPtr gets restacked as specified by aboveBelow and otherPtr.
5660
6304
 *
5661
6305
 *----------------------------------------------------------------------
5662
6306
 */
5663
6307
 
5664
6308
void
5665
 
TkWmRestackToplevel(winPtr, aboveBelow, otherPtr)
5666
 
    TkWindow *winPtr;           /* Window to restack. */
5667
 
    int aboveBelow;             /* Gives relative position for restacking;
 
6309
TkWmRestackToplevel(
 
6310
    TkWindow *winPtr,           /* Window to restack. */
 
6311
    int aboveBelow,             /* Gives relative position for restacking;
5668
6312
                                 * must be Above or Below. */
5669
 
    TkWindow *otherPtr;         /* Window relative to which to restack;
5670
 
                                 * if NULL, then winPtr gets restacked
5671
 
                                 * above or below *all* siblings. */
 
6313
    TkWindow *otherPtr)         /* Window relative to which to restack; if
 
6314
                                 * NULL, then winPtr gets restacked above or
 
6315
                                 * below *all* siblings. */
5672
6316
{
5673
6317
    XWindowChanges changes;
5674
6318
    unsigned int mask;
5681
6325
    /*
5682
6326
     * Make sure that winPtr and its wrapper window have been created.
5683
6327
     */
 
6328
 
5684
6329
    if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
5685
6330
        TkWmMapWindow(winPtr);
5686
6331
    }
5691
6336
         * The window is to be restacked with respect to another toplevel.
5692
6337
         * Make sure it has been created as well.
5693
6338
         */
 
6339
 
5694
6340
        if (otherPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
5695
6341
            TkWmMapWindow(otherPtr);
5696
6342
        }
5699
6345
    }
5700
6346
 
5701
6347
    /*
5702
 
     * Reconfigure the window.  Note that we use XReconfigureWMWindow
5703
 
     * instead of XConfigureWindow, in order to handle the case
5704
 
     * where the window is to be restacked with respect to another toplevel.
5705
 
     * See [ICCCM] 4.1.5 "Configuring the Window" and XReconfigureWMWindow(3)
5706
 
     * for details.
 
6348
     * Reconfigure the window. Note that we use XReconfigureWMWindow instead
 
6349
     * of XConfigureWindow, in order to handle the case where the window is to
 
6350
     * be restacked with respect to another toplevel. See [ICCCM] 4.1.5
 
6351
     * "Configuring the Window" and XReconfigureWMWindow(3) for details.
5707
6352
     */
5708
6353
 
5709
6354
    XReconfigureWMWindow(winPtr->display, wrapperPtr->window,
5710
 
            Tk_ScreenNumber((Tk_Window) winPtr), mask,  &changes);
 
6355
            Tk_ScreenNumber((Tk_Window) winPtr), mask, &changes);
5711
6356
}
5712
6357
 
5713
6358
 
5716
6361
 *
5717
6362
 * TkWmAddToColormapWindows --
5718
6363
 *
5719
 
 *      This procedure is called to add a given window to the
5720
 
 *      WM_COLORMAP_WINDOWS property for its top-level, if it
5721
 
 *      isn't already there.  It is invoked by the Tk code that
5722
 
 *      creates a new colormap, in order to make sure that colormap
5723
 
 *      information is propagated to the window manager by default.
 
6364
 *      This function is called to add a given window to the
 
6365
 *      WM_COLORMAP_WINDOWS property for its top-level, if it isn't already
 
6366
 *      there. It is invoked by the Tk code that creates a new colormap, in
 
6367
 *      order to make sure that colormap information is propagated to the
 
6368
 *      window manager by default.
5724
6369
 *
5725
6370
 * Results:
5726
6371
 *      None.
5727
6372
 *
5728
6373
 * Side effects:
5729
 
 *      WinPtr's window gets added to the WM_COLORMAP_WINDOWS
5730
 
 *      property of its nearest top-level ancestor, unless the
5731
 
 *      colormaps have been set explicitly with the
5732
 
 *      "wm colormapwindows" command.
 
6374
 *      WinPtr's window gets added to the WM_COLORMAP_WINDOWS property of its
 
6375
 *      nearest top-level ancestor, unless the colormaps have been set
 
6376
 *      explicitly with the "wm colormapwindows" command.
5733
6377
 *
5734
6378
 *----------------------------------------------------------------------
5735
6379
 */
5736
6380
 
5737
6381
void
5738
 
TkWmAddToColormapWindows(winPtr)
5739
 
    TkWindow *winPtr;           /* Window with a non-default colormap.
5740
 
                                 * Should not be a top-level window. */
 
6382
TkWmAddToColormapWindows(
 
6383
    TkWindow *winPtr)           /* Window with a non-default colormap. Should
 
6384
                                 * not be a top-level window. */
5741
6385
{
5742
6386
    TkWindow *wrapperPtr;
5743
6387
    TkWindow *topPtr;
5751
6395
    for (topPtr = winPtr->parentPtr; ; topPtr = topPtr->parentPtr) {
5752
6396
        if (topPtr == NULL) {
5753
6397
            /*
5754
 
             * Window is being deleted.  Skip the whole operation.
 
6398
             * Window is being deleted. Skip the whole operation.
5755
6399
             */
5756
6400
 
5757
6401
            return;
5793
6437
    }
5794
6438
 
5795
6439
    /*
5796
 
     * Make a new bigger array and use it to reset the property.
5797
 
     * Automatically add the toplevel itself as the last element
5798
 
     * of the list.
 
6440
     * Make a new bigger array and use it to reset the property. Automatically
 
6441
     * add the toplevel itself as the last element of the list.
5799
6442
     */
5800
6443
 
5801
6444
    newPtr = (Window *) ckalloc((unsigned) ((count+2)*sizeof(Window)));
5820
6463
 *
5821
6464
 * TkWmRemoveFromColormapWindows --
5822
6465
 *
5823
 
 *      This procedure is called to remove a given window from the
5824
 
 *      WM_COLORMAP_WINDOWS property for its top-level.  It is invoked
5825
 
 *      when windows are deleted.
 
6466
 *      This function is called to remove a given window from the
 
6467
 *      WM_COLORMAP_WINDOWS property for its top-level. It is invoked when
 
6468
 *      windows are deleted.
5826
6469
 *
5827
6470
 * Results:
5828
6471
 *      None.
5829
6472
 *
5830
6473
 * Side effects:
5831
 
 *      WinPtr's window gets removed from the WM_COLORMAP_WINDOWS
5832
 
 *      property of its nearest top-level ancestor, unless the
5833
 
 *      top-level itself is being deleted too.
 
6474
 *      WinPtr's window gets removed from the WM_COLORMAP_WINDOWS property of
 
6475
 *      its nearest top-level ancestor, unless the top-level itself is being
 
6476
 *      deleted too.
5834
6477
 *
5835
6478
 *----------------------------------------------------------------------
5836
6479
 */
5837
6480
 
5838
6481
void
5839
 
TkWmRemoveFromColormapWindows(winPtr)
5840
 
    TkWindow *winPtr;           /* Window that may be present in
 
6482
TkWmRemoveFromColormapWindows(
 
6483
    TkWindow *winPtr)           /* Window that may be present in
5841
6484
                                 * WM_COLORMAP_WINDOWS property for its
5842
 
                                 * top-level.  Should not be a top-level
 
6485
                                 * top-level. Should not be a top-level
5843
6486
                                 * window. */
5844
6487
{
5845
6488
    TkWindow *wrapperPtr;
5866
6509
    }
5867
6510
    if (topPtr->flags & TK_ALREADY_DEAD) {
5868
6511
        /*
5869
 
         * Top-level is being deleted, so there's no need to cleanup
5870
 
         * the WM_COLORMAP_WINDOWS property.
 
6512
         * Top-level is being deleted, so there's no need to cleanup the
 
6513
         * WM_COLORMAP_WINDOWS property.
5871
6514
         */
5872
6515
 
5873
6516
        return;
5894
6537
    }
5895
6538
 
5896
6539
    /*
5897
 
     * Find the window and slide the following ones down to cover
5898
 
     * it up.
 
6540
     * Find the window and slide the following ones down to cover it up.
5899
6541
     */
5900
6542
 
5901
6543
    for (i = 0; i < count; i++) {
5919
6561
 *      Fetch the position of the mouse pointer.
5920
6562
 *
5921
6563
 * Results:
5922
 
 *      *xPtr and *yPtr are filled in with the (virtual) root coordinates
5923
 
 *      of the mouse pointer for tkwin's display.  If the pointer isn't
5924
 
 *      on tkwin's screen, then -1 values are returned for both
5925
 
 *      coordinates.  The argument tkwin must be a toplevel window.
 
6564
 *      *xPtr and *yPtr are filled in with the (virtual) root coordinates of
 
6565
 *      the mouse pointer for tkwin's display. If the pointer isn't on tkwin's
 
6566
 *      screen, then -1 values are returned for both coordinates. The argument
 
6567
 *      tkwin must be a toplevel window.
5926
6568
 *
5927
6569
 * Side effects:
5928
6570
 *      None.
5931
6573
 */
5932
6574
 
5933
6575
void
5934
 
TkGetPointerCoords(tkwin, xPtr, yPtr)
5935
 
    Tk_Window tkwin;            /* Toplevel window that identifies screen
5936
 
                                 * on which lookup is to be done. */
5937
 
    int *xPtr, *yPtr;           /* Store pointer coordinates here. */
 
6576
TkGetPointerCoords(
 
6577
    Tk_Window tkwin,            /* Toplevel window that identifies screen on
 
6578
                                 * which lookup is to be done. */
 
6579
    int *xPtr, int *yPtr)       /* Store pointer coordinates here. */
5938
6580
{
5939
6581
    TkWindow *winPtr = (TkWindow *) tkwin;
5940
6582
    WmInfo *wmPtr;
5960
6602
 *
5961
6603
 * GetMaxSize --
5962
6604
 *
5963
 
 *      This procedure computes the current maxWidth and maxHeight
5964
 
 *      values for a window, taking into account the possibility
5965
 
 *      that they may be defaulted.
 
6605
 *      This function computes the current maxWidth and maxHeight values for a
 
6606
 *      window, taking into account the possibility that they may be
 
6607
 *      defaulted.
5966
6608
 *
5967
6609
 * Results:
5968
 
 *      The values at *maxWidthPtr and *maxHeightPtr are filled
5969
 
 *      in with the maximum allowable dimensions of wmPtr's window,
5970
 
 *      in grid units.  If no maximum has been specified for the
5971
 
 *      window, then this procedure computes the largest sizes that
5972
 
 *      will fit on the screen.
 
6610
 *      The values at *maxWidthPtr and *maxHeightPtr are filled in with the
 
6611
 *      maximum allowable dimensions of wmPtr's window, in grid units. If no
 
6612
 *      maximum has been specified for the window, then this function computes
 
6613
 *      the largest sizes that will fit on the screen.
5973
6614
 *
5974
6615
 * Side effects:
5975
6616
 *      None.
5978
6619
 */
5979
6620
 
5980
6621
static void
5981
 
GetMaxSize(wmPtr, maxWidthPtr, maxHeightPtr)
5982
 
    WmInfo *wmPtr;              /* Window manager information for the
 
6622
GetMaxSize(
 
6623
    WmInfo *wmPtr,              /* Window manager information for the
5983
6624
                                 * window. */
5984
 
    int *maxWidthPtr;           /* Where to store the current maximum
5985
 
                                 * width of the window. */
5986
 
    int *maxHeightPtr;          /* Where to store the current maximum
5987
 
                                 * height of the window. */
 
6625
    int *maxWidthPtr,           /* Where to store the current maximum width of
 
6626
                                 * the window. */
 
6627
    int *maxHeightPtr)          /* Where to store the current maximum height
 
6628
                                 * of the window. */
5988
6629
{
5989
6630
    int tmp;
5990
6631
 
5992
6633
        *maxWidthPtr = wmPtr->maxWidth;
5993
6634
    } else {
5994
6635
        /*
5995
 
         * Must compute a default width.  Fill up the display, leaving a
5996
 
         * bit of extra space for the window manager's borders.
 
6636
         * Must compute a default width. Fill up the display, leaving a bit of
 
6637
         * extra space for the window manager's borders.
5997
6638
         */
5998
6639
 
5999
6640
        tmp = DisplayWidth(wmPtr->winPtr->display, wmPtr->winPtr->screenNum)
6000
6641
            - 15;
6001
6642
        if (wmPtr->gridWin != NULL) {
6002
6643
            /*
6003
 
             * Gridding is turned on;  convert from pixels to grid units.
 
6644
             * Gridding is turned on; convert from pixels to grid units.
6004
6645
             */
6005
6646
 
6006
6647
            tmp = wmPtr->reqGridWidth
6026
6667
 *
6027
6668
 * TkpMakeMenuWindow --
6028
6669
 *
6029
 
 *      Configure the window to be either a pull-down (or pop-up)
6030
 
 *      menu, or as a toplevel (torn-off) menu or palette.
 
6670
 *      Configure the window to be either a pull-down (or pop-up) menu, or as
 
6671
 *      a toplevel (torn-off) menu or palette.
6031
6672
 *
6032
6673
 * Results:
6033
6674
 *      None.
6039
6680
 */
6040
6681
 
6041
6682
void
6042
 
TkpMakeMenuWindow(tkwin, transient)
6043
 
    Tk_Window tkwin;            /* New window. */
6044
 
    int transient;              /* 1 means menu is only posted briefly as
6045
 
                                 * a popup or pulldown or cascade.  0 means
6046
 
                                 * menu is always visible, e.g. as a torn-off
6047
 
                                 * menu.  Determines whether save_under and
 
6683
TkpMakeMenuWindow(
 
6684
    Tk_Window tkwin,            /* New window. */
 
6685
    int transient)              /* 1 means menu is only posted briefly as a
 
6686
                                 * popup or pulldown or cascade. 0 means menu
 
6687
                                 * is always visible, e.g. as a torn-off menu.
 
6688
                                 * Determines whether save_under and
6048
6689
                                 * override_redirect should be set. */
6049
6690
{
6050
6691
    WmInfo *wmPtr;
6068
6709
    }
6069
6710
 
6070
6711
    /*
6071
 
     * The override-redirect and save-under bits must be set on the
6072
 
     * wrapper window in order to have the desired effect.  However,
6073
 
     * also set the override-redirect bit on the window itself, so
6074
 
     * that the "wm overrideredirect" command will see it.
 
6712
     * The override-redirect and save-under bits must be set on the wrapper
 
6713
     * window in order to have the desired effect. However, also set the
 
6714
     * override-redirect bit on the window itself, so that the "wm
 
6715
     * overrideredirect" command will see it.
6075
6716
     */
6076
6717
 
6077
 
    if ((atts.override_redirect != Tk_Attributes(wrapperPtr)->override_redirect)
 
6718
    if ((atts.override_redirect!=Tk_Attributes(wrapperPtr)->override_redirect)
6078
6719
            || (atts.save_under != Tk_Attributes(wrapperPtr)->save_under)) {
6079
6720
        Tk_ChangeWindowAttributes((Tk_Window) wrapperPtr,
6080
6721
                CWOverrideRedirect|CWSaveUnder, &atts);
6091
6732
 *
6092
6733
 * CreateWrapper --
6093
6734
 *
6094
 
 *      This procedure is invoked to create the wrapper window for a
6095
 
 *      toplevel window.  It is called just before a toplevel is mapped
6096
 
 *      for the first time.
 
6735
 *      This function is invoked to create the wrapper window for a toplevel
 
6736
 *      window. It is called just before a toplevel is mapped for the first
 
6737
 *      time.
6097
6738
 *
6098
6739
 * Results:
6099
6740
 *      None.
6105
6746
 */
6106
6747
 
6107
6748
static void
6108
 
CreateWrapper(wmPtr)
6109
 
    WmInfo *wmPtr;              /* Window manager information for the
 
6749
CreateWrapper(
 
6750
    WmInfo *wmPtr)              /* Window manager information for the
6110
6751
                                 * window. */
6111
6752
{
6112
6753
    TkWindow *winPtr, *wrapperPtr;
6120
6761
    }
6121
6762
 
6122
6763
    /*
6123
 
     * The code below is copied from CreateTopLevelWindow,
6124
 
     * Tk_MakeWindowExist, and TkpMakeWindow; The idea is to create an
6125
 
     * "official" Tk window (so that we can get events on it), but to
6126
 
     * hide the window outside the official Tk hierarchy so that it
6127
 
     * isn't visible to the application.  See the comments for the other
6128
 
     * procedures if you have questions about this code.
 
6764
     * The code below is copied from CreateTopLevelWindow, Tk_MakeWindowExist,
 
6765
     * and TkpMakeWindow. The idea is to create an "official" Tk window (so
 
6766
     * that we can get events on it), but to hide the window outside the
 
6767
     * official Tk hierarchy so that it isn't visible to the application. See
 
6768
     * the comments for the other functions if you have questions about this
 
6769
     * code.
6129
6770
     */
6130
6771
 
6131
6772
    wmPtr->wrapperPtr = wrapperPtr = TkAllocWindow(winPtr->dispPtr,
6133
6774
    wrapperPtr->dirtyAtts |= CWBorderPixel;
6134
6775
 
6135
6776
    /*
6136
 
     * Tk doesn't normally select for StructureNotifyMask events because
6137
 
     * the events are synthesized internally.  However, for wrapper
6138
 
     * windows we need to know when the window manager modifies the
6139
 
     * window configuration.  We also need to select on focus change
6140
 
     * events; these are the only windows for which we care about focus
6141
 
     * changes.
 
6777
     * Tk doesn't normally select for StructureNotifyMask events because the
 
6778
     * events are synthesized internally. However, for wrapper windows we need
 
6779
     * to know when the window manager modifies the window configuration. We
 
6780
     * also need to select on focus change events; these are the only windows
 
6781
     * for which we care about focus changes.
6142
6782
     */
6143
6783
 
6144
6784
    wrapperPtr->flags |= TK_WRAPPER;
6173
6813
            0, 0);
6174
6814
 
6175
6815
    /*
6176
 
     * Tk must monitor structure events for wrapper windows in order
6177
 
     * to detect changes made by window managers such as resizing,
6178
 
     * mapping, unmapping, etc..
 
6816
     * Tk must monitor structure events for wrapper windows in order to detect
 
6817
     * changes made by window managers such as resizing, mapping, unmapping,
 
6818
     * etc..
6179
6819
     */
6180
6820
 
6181
 
    Tk_CreateEventHandler((Tk_Window) wmPtr->wrapperPtr, StructureNotifyMask,
6182
 
            WrapperEventProc, (ClientData) wmPtr);
 
6821
    Tk_CreateEventHandler((Tk_Window) wmPtr->wrapperPtr, 
 
6822
            WrapperEventMask, WrapperEventProc, (ClientData) wmPtr);
6183
6823
}
6184
6824
 
6185
6825
/*
6187
6827
 *
6188
6828
 * TkWmFocusToplevel --
6189
6829
 *
6190
 
 *      This is a utility procedure invoked by focus-management code.
6191
 
 *      The focus code responds to externally generated focus-related
6192
 
 *      events on wrapper windows but ignores those events for any other
6193
 
 *      windows.  This procedure determines whether a given window is a
6194
 
 *      wrapper window and, if so, returns the toplevel window
6195
 
 *      corresponding to the wrapper.
 
6830
 *      This is a utility function invoked by focus-management code. The focus
 
6831
 *      code responds to externally generated focus-related events on wrapper
 
6832
 *      windows but ignores those events for any other windows. This function
 
6833
 *      determines whether a given window is a wrapper window and, if so,
 
6834
 *      returns the toplevel window corresponding to the wrapper.
6196
6835
 *
6197
6836
 * Results:
6198
 
 *      If winPtr is a wrapper window, returns a pointer to the
6199
 
 *      corresponding toplevel window; otherwise returns NULL.
 
6837
 *      If winPtr is a wrapper window, returns a pointer to the corresponding
 
6838
 *      toplevel window; otherwise returns NULL.
6200
6839
 *
6201
6840
 * Side effects:
6202
6841
 *      None.
6205
6844
 */
6206
6845
 
6207
6846
TkWindow *
6208
 
TkWmFocusToplevel(winPtr)
6209
 
    TkWindow *winPtr;           /* Window that received a focus-related
 
6847
TkWmFocusToplevel(
 
6848
    TkWindow *winPtr)           /* Window that received a focus-related
6210
6849
                                 * event. */
6211
6850
{
6212
6851
    if (!(winPtr->flags & TK_WRAPPER)) {
6220
6859
 *
6221
6860
 * TkUnixSetMenubar --
6222
6861
 *
6223
 
 *      This procedure is invoked by menu management code to specify the
6224
 
 *      window to use as a menubar for a given toplevel window.
 
6862
 *      This function is invoked by menu management code to specify the window
 
6863
 *      to use as a menubar for a given toplevel window.
6225
6864
 *
6226
6865
 * Results:
6227
6866
 *      None.
6228
6867
 *
6229
6868
 * Side effects:
6230
 
 *      The window given by menubar will be mapped and positioned inside
6231
 
 *      the wrapper for tkwin and above tkwin.  Menubar will
6232
 
 *      automatically be resized to maintain the height specified by
6233
 
 *      TkUnixSetMenuHeight the same width as tkwin.  Any previous
6234
 
 *      menubar specified for tkwin will be unmapped and ignored from
6235
 
 *      now on.
 
6869
 *      The window given by menubar will be mapped and positioned inside the
 
6870
 *      wrapper for tkwin and above tkwin. Menubar will automatically be
 
6871
 *      resized to maintain the height specified by TkUnixSetMenuHeight the
 
6872
 *      same width as tkwin. Any previous menubar specified for tkwin will be
 
6873
 *      unmapped and ignored from now on.
6236
6874
 *
6237
6875
 *----------------------------------------------------------------------
6238
6876
 */
6239
6877
 
6240
6878
void
6241
 
TkUnixSetMenubar(tkwin, menubar)
6242
 
    Tk_Window tkwin;            /* Token for toplevel window. */
6243
 
    Tk_Window menubar;          /* Token for window that is to serve as
6244
 
                                 * menubar for tkwin.  Must not be a
6245
 
                                 * toplevel window.  If NULL, any
6246
 
                                 * existing menubar is canceled and the
6247
 
                                 * menu height is reset to 0. */
 
6879
TkUnixSetMenubar(
 
6880
    Tk_Window tkwin,            /* Token for toplevel window. */
 
6881
    Tk_Window menubar)          /* Token for window that is to serve as
 
6882
                                 * menubar for tkwin. Must not be a toplevel
 
6883
                                 * window. If NULL, any existing menubar is
 
6884
                                 * canceled and the menu height is reset to
 
6885
                                 * 0. */
6248
6886
{
6249
6887
    WmInfo *wmPtr = ((TkWindow *) tkwin)->wmInfoPtr;
6250
6888
    Tk_Window parent;
6256
6894
 
6257
6895
    if (wmPtr->menubar != NULL) {
6258
6896
        /*
6259
 
         * There's already a menubar for this toplevel.  If it isn't the
6260
 
         * same as the new menubar, unmap it so that it is out of the
6261
 
         * way, and reparent it back to its original parent.
 
6897
         * There's already a menubar for this toplevel. If it isn't the same
 
6898
         * as the new menubar, unmap it so that it is out of the way, and
 
6899
         * reparent it back to its original parent.
6262
6900
         */
6263
6901
 
6264
6902
        if (wmPtr->menubar == menubar) {
6275
6913
        }
6276
6914
        Tk_DeleteEventHandler(wmPtr->menubar, StructureNotifyMask,
6277
6915
                MenubarDestroyProc, (ClientData) wmPtr->menubar);
6278
 
        Tk_ManageGeometry(wmPtr->menubar, NULL, (ClientData) NULL);
 
6916
        Tk_ManageGeometry(wmPtr->menubar, NULL, NULL);
6279
6917
    }
6280
6918
 
6281
6919
    wmPtr->menubar = menubar;
6283
6921
        wmPtr->menuHeight = 0;
6284
6922
    } else {
6285
6923
        if ((menubarPtr->flags & TK_TOP_LEVEL)
6286
 
             || (Tk_Screen(menubar) != Tk_Screen(tkwin))) {
6287
 
            panic("TkUnixSetMenubar got bad menubar");
 
6924
                || (Tk_Screen(menubar) != Tk_Screen(tkwin))) {
 
6925
            Tcl_Panic("TkUnixSetMenubar got bad menubar");
6288
6926
        }
6289
6927
        wmPtr->menuHeight = Tk_ReqHeight(menubar);
6290
6928
        if (wmPtr->menuHeight == 0) {
6317
6955
 *
6318
6956
 * MenubarDestroyProc --
6319
6957
 *
6320
 
 *      This procedure is invoked by the event dispatcher whenever a
6321
 
 *      menubar window is destroyed (it's also invoked for a few other
6322
 
 *      kinds of events, but we ignore those).
 
6958
 *      This function is invoked by the event dispatcher whenever a menubar
 
6959
 *      window is destroyed (it's also invoked for a few other kinds of
 
6960
 *      events, but we ignore those).
6323
6961
 *
6324
6962
 * Results:
6325
6963
 *      None.
6326
6964
 *
6327
6965
 * Side effects:
6328
 
 *      The association between the window and its toplevel is broken,
6329
 
 *      so that the window is no longer considered to be a menubar.
 
6966
 *      The association between the window and its toplevel is broken, so that
 
6967
 *      the window is no longer considered to be a menubar.
6330
6968
 *
6331
6969
 *----------------------------------------------------------------------
6332
6970
 */
6333
6971
 
6334
6972
static void
6335
 
MenubarDestroyProc(clientData, eventPtr)
6336
 
    ClientData clientData;              /* TkWindow pointer for menubar. */
6337
 
    XEvent *eventPtr;                   /* Describes what just happened. */
 
6973
MenubarDestroyProc(
 
6974
    ClientData clientData,      /* TkWindow pointer for menubar. */
 
6975
    XEvent *eventPtr)           /* Describes what just happened. */
6338
6976
{
6339
6977
    WmInfo *wmPtr;
6340
6978
 
6356
6994
 *
6357
6995
 * MenubarReqProc --
6358
6996
 *
6359
 
 *      This procedure is invoked by the Tk geometry management code
6360
 
 *      whenever a menubar calls Tk_GeometryRequest to request a new
6361
 
 *      size.
 
6997
 *      This function is invoked by the Tk geometry management code whenever a
 
6998
 *      menubar calls Tk_GeometryRequest to request a new size.
6362
6999
 *
6363
7000
 * Results:
6364
7001
 *      None.
6370
7007
 */
6371
7008
 
6372
7009
static void
6373
 
MenubarReqProc(clientData, tkwin)
6374
 
    ClientData clientData;      /* Pointer to the window manager
6375
 
                                 * information for tkwin's toplevel. */
6376
 
    Tk_Window tkwin;            /* Handle for menubar window. */
 
7010
MenubarReqProc(
 
7011
    ClientData clientData,      /* Pointer to the window manager information
 
7012
                                 * for tkwin's toplevel. */
 
7013
    Tk_Window tkwin)            /* Handle for menubar window. */
6377
7014
{
6378
7015
    WmInfo *wmPtr = (WmInfo *) clientData;
6379
7016
 
6393
7030
 *
6394
7031
 * TkpGetWrapperWindow --
6395
7032
 *
6396
 
 *      Given a toplevel window return the hidden wrapper window for
6397
 
 *      the toplevel window if available.
 
7033
 *      Given a toplevel window return the hidden wrapper window for the
 
7034
 *      toplevel window if available.
6398
7035
 *
6399
7036
 * Results:
6400
 
 *      The wrapper window.  NULL is we were not passed a toplevel
6401
 
 *      window or the wrapper has yet to be created.
 
7037
 *      The wrapper window. NULL is we were not passed a toplevel window or
 
7038
 *      the wrapper has yet to be created.
6402
7039
 *
6403
7040
 * Side effects:
6404
7041
 *      None.
6407
7044
 */
6408
7045
 
6409
7046
TkWindow *
6410
 
TkpGetWrapperWindow(winPtr)
6411
 
    TkWindow *winPtr;           /* A toplevel window pointer. */
 
7047
TkpGetWrapperWindow(
 
7048
    TkWindow *winPtr)           /* A toplevel window pointer. */
6412
7049
{
6413
7050
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
6414
7051
 
6565
7202
 *
6566
7203
 * UpdateCommand --
6567
7204
 *
6568
 
 *      Update the WM_COMMAND property, taking care to translate
6569
 
 *      the command strings into the external encoding.
 
7205
 *      Update the WM_COMMAND property, taking care to translate the command
 
7206
 *      strings into the external encoding.
6570
7207
 *
6571
7208
 * Results:
6572
7209
 *      None.
6578
7215
 */
6579
7216
 
6580
7217
static void
6581
 
UpdateCommand(winPtr)
6582
 
    TkWindow  *winPtr;
 
7218
UpdateCommand(
 
7219
    TkWindow *winPtr)
6583
7220
{
6584
7221
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
6585
7222
    Tcl_DString cmds, ds;
6588
7225
    int  cmdArgc;
6589
7226
 
6590
7227
    /*
6591
 
     * Translate the argv strings into the external encoding.  To avoid
6592
 
     * allocating lots of memory, the strings are appended to a buffer
6593
 
     * with nulls between each string.
 
7228
     * Translate the argv strings into the external encoding. To avoid
 
7229
     * allocating lots of memory, the strings are appended to a buffer with
 
7230
     * nulls between each string.
6594
7231
     *
6595
 
     * This code is tricky because we need to pass and array of pointers
6596
 
     * to XSetCommand.  However, we can't compute the pointers as we go
6597
 
     * because the DString buffer space could get reallocated.  So, store
6598
 
     * offsets for each element as we go, then compute pointers from the
6599
 
     * offsets once the entire DString is done.
 
7232
     * This code is tricky because we need to pass and array of pointers to
 
7233
     * XSetCommand. However, we can't compute the pointers as we go because
 
7234
     * the DString buffer space could get reallocated. So, store offsets for
 
7235
     * each element as we go, then compute pointers from the offsets once the
 
7236
     * entire DString is done.
6600
7237
     */
6601
7238
#ifdef _LANG
6602
7239
    Tcl_Obj **cmdObjv;
6639
7276
 *
6640
7277
 * TkpWmSetState --
6641
7278
 *
6642
 
 *      Sets the window manager state for the wrapper window of a
6643
 
 *      given toplevel window.
 
7279
 *      Sets the window manager state for the wrapper window of a given
 
7280
 *      toplevel window.
6644
7281
 *
6645
7282
 * Results:
6646
7283
 *      0 on error, 1 otherwise
6652
7289
 */
6653
7290
 
6654
7291
int
6655
 
TkpWmSetState(winPtr, state)
6656
 
     TkWindow *winPtr;          /* Toplevel window to operate on. */
6657
 
     int state;                 /* One of IconicState, NormalState,
6658
 
                                 * or WithdrawnState. */
 
7292
TkpWmSetState(
 
7293
     TkWindow *winPtr,          /* Toplevel window to operate on. */
 
7294
     int state)                 /* One of IconicState, NormalState, or
 
7295
                                 * WithdrawnState. */
6659
7296
{
6660
7297
    WmInfo *wmPtr = winPtr->wmInfoPtr;
6661
7298
 
6662
7299
    if (state == WithdrawnState) {
6663
 
        wmPtr->hints.initial_state = WithdrawnState;
6664
 
        wmPtr->withdrawn = 1;
6665
 
        if (wmPtr->flags & WM_NEVER_MAPPED) {
6666
 
            return 1;
6667
 
        }
6668
 
        if (XWithdrawWindow(winPtr->display, wmPtr->wrapperPtr->window,
6669
 
                winPtr->screenNum) == 0) {
6670
 
            return 0;
6671
 
        }
6672
 
        WaitForMapNotify(winPtr, 0);
 
7300
        wmPtr->hints.initial_state = WithdrawnState;
 
7301
        wmPtr->withdrawn = 1;
 
7302
        if (wmPtr->flags & WM_NEVER_MAPPED) {
 
7303
            return 1;
 
7304
        }
 
7305
        if (XWithdrawWindow(winPtr->display, wmPtr->wrapperPtr->window,
 
7306
                winPtr->screenNum) == 0) {
 
7307
            return 0;
 
7308
        }
 
7309
        WaitForMapNotify(winPtr, 0);
6673
7310
    } else if (state == NormalState) {
6674
 
        wmPtr->hints.initial_state = NormalState;
6675
 
        wmPtr->withdrawn = 0;
6676
 
        if (wmPtr->flags & WM_NEVER_MAPPED) {
6677
 
            return 1;
6678
 
        }
6679
 
        UpdateHints(winPtr);
6680
 
        Tk_MapWindow((Tk_Window) winPtr);
 
7311
        wmPtr->hints.initial_state = NormalState;
 
7312
        wmPtr->withdrawn = 0;
 
7313
        if (wmPtr->flags & WM_NEVER_MAPPED) {
 
7314
            return 1;
 
7315
        }
 
7316
        UpdateHints(winPtr);
 
7317
        Tk_MapWindow((Tk_Window) winPtr);
6681
7318
    } else if (state == IconicState) {
6682
 
        wmPtr->hints.initial_state = IconicState;
6683
 
        if (wmPtr->flags & WM_NEVER_MAPPED) {
6684
 
            return 1;
6685
 
        }
6686
 
        if (wmPtr->withdrawn) {
6687
 
            UpdateHints(winPtr);
6688
 
            Tk_MapWindow((Tk_Window) winPtr);
6689
 
            wmPtr->withdrawn = 0;
6690
 
        } else {
6691
 
            if (XIconifyWindow(winPtr->display, wmPtr->wrapperPtr->window,
6692
 
                    winPtr->screenNum) == 0) {
6693
 
                return 0;
6694
 
            }
6695
 
            WaitForMapNotify(winPtr, 0);
6696
 
        }
 
7319
        wmPtr->hints.initial_state = IconicState;
 
7320
        if (wmPtr->flags & WM_NEVER_MAPPED) {
 
7321
            return 1;
 
7322
        }
 
7323
        if (wmPtr->withdrawn) {
 
7324
            UpdateHints(winPtr);
 
7325
            Tk_MapWindow((Tk_Window) winPtr);
 
7326
            wmPtr->withdrawn = 0;
 
7327
        } else {
 
7328
            if (XIconifyWindow(winPtr->display, wmPtr->wrapperPtr->window,
 
7329
                    winPtr->screenNum) == 0) {
 
7330
                return 0;
 
7331
            }
 
7332
            WaitForMapNotify(winPtr, 0);
 
7333
        }
6697
7334
    }
6698
7335
 
6699
7336
    return 1;