-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathtkUnixWm.c
More file actions
7519 lines (6876 loc) · 219 KB
/
tkUnixWm.c
File metadata and controls
7519 lines (6876 loc) · 219 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* tkUnixWm.c --
*
* This module takes care of the interactions between a Tk-based
* application and the window manager. Among other things, it implements
* the "wm" command and passes geometry information to the window
* manager.
*
* Copyright © 1991-1994 The Regents of the University of California.
* Copyright © 1994-1997 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tkUnixInt.h"
/*
* A data structure of the following type holds information for each window
* manager protocol (such as WM_DELETE_WINDOW) for which a handler (i.e. a Tcl
* command) has been defined for a particular top-level window.
*/
typedef struct ProtocolHandler {
Atom protocol; /* Identifies the protocol. */
struct ProtocolHandler *nextPtr;
/* Next in list of protocol handlers for the
* same top-level window, or NULL for end of
* list. */
Tcl_Interp *interp; /* Interpreter in which to invoke command. */
char command[TKFLEXARRAY]; /* Tcl command to invoke when a client message
* for this protocol arrives. The actual size
* of the structure varies to accommodate the
* needs of the actual command. THIS MUST BE
* THE LAST FIELD OF THE STRUCTURE. */
} ProtocolHandler;
#define HANDLER_SIZE(cmdLength) \
(offsetof(ProtocolHandler, command) + 1 + cmdLength)
/*
* Data for [wm attributes] command:
*/
typedef struct {
double alpha; /* Transparency; 0.0=transparent, 1.0=opaque */
int topmost; /* Flag: true=>stay-on-top */
int zoomed; /* Flag: true=>maximized */
int fullscreen; /* Flag: true=>fullscreen */
} WmAttributes;
typedef enum {
WMATT_ALPHA, WMATT_FULLSCREEN, WMATT_TOPMOST, WMATT_TYPE,
WMATT_ZOOMED, _WMATT_LAST_ATTRIBUTE
} WmAttribute;
static const char *const WmAttributeNames[] = {
"-alpha", "-fullscreen", "-topmost", "-type",
"-zoomed", NULL
};
/*
* A data structure of the following type holds window-manager-related
* information for each top-level window in an application.
*/
typedef struct TkWmInfo {
TkWindow *winPtr; /* Pointer to main Tk information for this
* window. */
Window reparent; /* If the window has been reparented, this
* gives the ID of the ancestor of the window
* that is a child of the root window (may not
* be window's immediate parent). If the
* window isn't reparented, this has the value
* None. */
char *title; /* Title to display in window caption. If
* NULL, use name of widget. Malloced. */
char *iconName; /* Name to display in icon. Malloced. */
XWMHints hints; /* Various pieces of information for window
* manager. */
char *leaderName; /* Path name of leader of window group
* (corresponds to hints.window_group).
* Malloc-ed. Note: this field doesn't get
* updated if leader is destroyed. */
TkWindow *containerPtr; /* Container window for TRANSIENT_FOR property,
* or NULL. */
Tk_Window icon; /* Window to use as icon for this window, or
* NULL. */
Tk_Window iconFor; /* Window for which this window is icon, or
* NULL if this isn't an icon for anyone. */
int withdrawn; /* Non-zero means window has been withdrawn. */
/*
* In order to support menubars transparently under X, each toplevel
* window is encased in an additional window, called the wrapper, that
* holds the toplevel and the menubar, if any. The information below is
* used to keep track of the wrapper and the menubar.
*/
TkWindow *wrapperPtr; /* Pointer to information about the wrapper.
* This is the "real" toplevel window as seen
* by the window manager. Although this is an
* official Tk window, it doesn't appear in
* the application's window hierarchy. NULL
* means that the wrapper hasn't been created
* yet. */
Tk_Window menubar; /* Pointer to information about the menubar,
* or NULL if there is no menubar for this
* toplevel. */
int menuHeight; /* Amount of vertical space needed for
* menubar, measured in pixels. If menubar is
* non-NULL, this is >= 1 (X servers don't
* like dimensions of 0). */
/*
* Information used to construct an XSizeHints structure for the window
* manager:
*/
int sizeHintsFlags; /* Flags word for XSizeHints structure. If the
* PBaseSize flag is set then the window is
* gridded; otherwise it isn't gridded. */
int minWidth, minHeight; /* Minimum dimensions of window, in pixels or
* grid units. */
int maxWidth, maxHeight; /* Maximum dimensions of window, in pixels or
* grid units. 0 to default.*/
Tk_Window gridWin; /* Identifies the window that controls
* gridding for this top-level, or NULL if the
* top-level isn't currently gridded. */
int widthInc, heightInc; /* Increments for size changes (# pixels per
* step). */
struct {
int x; /* numerator */
int y; /* denominator */
} minAspect, maxAspect; /* Min/max aspect ratios for window. */
int reqGridWidth, reqGridHeight;
/* The dimensions of the window (in grid
* units) requested through the geometry
* manager. */
int gravity; /* Desired window gravity. */
/*
* Information used to manage the size and location of a window.
*/
int width, height; /* Desired dimensions of window, specified in
* pixels or grid units. These values are set
* by the "wm geometry" command and by
* ConfigureNotify events (for when wm resizes
* window). -1 means user hasn't requested
* dimensions. */
int x, y; /* Desired X and Y coordinates for window.
* These values are set by "wm geometry", plus
* by ConfigureNotify events (when wm moves
* window). These numbers are different than
* the numbers stored in winPtr->changes
* because (a) they could be measured from the
* right or bottom edge of the screen (see
* WM_NEGATIVE_X and WM_NEGATIVE_Y flags) and
* (b) if the window has been reparented then
* they refer to the parent rather than the
* window itself. */
int parentWidth, parentHeight;
/* Width and height of reparent, in pixels
* *including border*. If window hasn't been
* reparented then these will be the outer
* dimensions of the window, including
* border. */
int xInParent, yInParent; /* Offset of wrapperPtr within reparent,
* measured in pixels from upper-left outer
* corner of reparent's border to upper-left
* outer corner of wrapperPtr's border. If not
* reparented then these are zero. */
int configWidth, configHeight;
/* Dimensions passed to last request that we
* issued to change geometry of the wrapper.
* Used to eliminate redundant resize
* operations. */
/*
* Information about the virtual root window for this top-level, if there
* is one.
*/
Window vRoot; /* Virtual root window for this top-level, or
* None if there is no virtual root window
* (i.e. just use the screen's root). */
int vRootX, vRootY; /* Position of the virtual root inside the
* root window. If the WM_VROOT_OFFSET_STALE
* flag is set then this information may be
* incorrect and needs to be refreshed from
* the X server. If vRoot is None then these
* values are both 0. */
int vRootWidth, vRootHeight;/* Dimensions of the virtual root window. If
* vRoot is None, gives the dimensions of the
* containing screen. This information is
* never stale, even though vRootX and vRootY
* can be. */
/*
* Miscellaneous information.
*/
WmAttributes attributes; /* Current state of [wm attributes] */
WmAttributes reqState; /* Requested state of [wm attributes] */
ProtocolHandler *protPtr; /* First in list of protocol handlers for this
* window (NULL means none). */
Tcl_Size cmdArgc; /* Number of elements in cmdArgv below. */
const char **cmdArgv; /* Array of strings to store in the WM_COMMAND
* property. NULL means nothing available. */
char *clientMachine; /* String to store in WM_CLIENT_MACHINE
* property, or NULL. */
int flags; /* Miscellaneous flags, defined below. */
int numTransients; /* number of transients on this window */
int iconDataSize; /* size of iconphoto image data */
unsigned char *iconDataPtr; /* iconphoto image data, if set */
struct TkWmInfo *nextPtr; /* Next in list of all top-level windows. */
} WmInfo;
/*
* Flag values for WmInfo structures:
*
* WM_NEVER_MAPPED - non-zero means window has never been mapped;
* need to update all info when window is first
* mapped.
* WM_UPDATE_PENDING - non-zero means a call to UpdateGeometryInfo
* has already been scheduled for this window;
* no need to schedule another one.
* WM_NEGATIVE_X - non-zero means x-coordinate is measured in
* pixels from right edge of screen, rather than
* from left edge.
* WM_NEGATIVE_Y - non-zero means y-coordinate is measured in
* pixels up from bottom of screen, rather than
* down from top.
* WM_UPDATE_SIZE_HINTS - non-zero means that new size hints need to be
* propagated to window manager.
* WM_SYNC_PENDING - set to non-zero while waiting for the window
* manager to respond to some state change.
* WM_VROOT_OFFSET_STALE - non-zero means that (x,y) offset information
* about the virtual root window is stale and
* needs to be fetched fresh from the X server.
* WM_ABOUT_TO_MAP - non-zero means that the window is about to be
* mapped by TkWmMapWindow. This is used by
* UpdateGeometryInfo to modify its behavior.
* WM_MOVE_PENDING - non-zero means the application has requested a
* new position for the window, but it hasn't
* been reflected through the window manager yet.
* WM_COLORMAPS_EXPLICIT - non-zero means the colormap windows were set
* explicitly via "wm colormapwindows".
* WM_ADDED_TOPLEVEL_COLORMAP - non-zero means that when "wm colormapwindows"
* was called the top-level itself wasn't
* specified, so we added it implicitly at the
* end of the list.
* WM_WIDTH_NOT_RESIZABLE - non-zero means that we're not supposed to
* allow the user to change the width of the
* window (controlled by "wm resizable" command).
* WM_HEIGHT_NOT_RESIZABLE - non-zero means that we're not supposed to
* allow the user to change the height of the
* window (controlled by "wm resizable" command).
* WM_WITHDRAWN - non-zero means that this window has explicitly
* been withdrawn. If it's a transient, it should
* not mirror state changes in the container.
*/
#define WM_NEVER_MAPPED 1
#define WM_UPDATE_PENDING 2
#define WM_NEGATIVE_X 4
#define WM_NEGATIVE_Y 8
#define WM_UPDATE_SIZE_HINTS 0x10
#define WM_SYNC_PENDING 0x20
#define WM_VROOT_OFFSET_STALE 0x40
#define WM_ABOUT_TO_MAP 0x100
#define WM_MOVE_PENDING 0x200
#define WM_COLORMAPS_EXPLICIT 0x400
#define WM_ADDED_TOPLEVEL_COLORMAP 0x800
#define WM_WIDTH_NOT_RESIZABLE 0x1000
#define WM_HEIGHT_NOT_RESIZABLE 0x2000
#define WM_WITHDRAWN 0x4000
/*
* Wrapper for XGetWindowProperty and XChangeProperty to make them a *bit*
* less verbose.
*/
#define GetWindowProperty(wrapperPtr, atom, length, type, typePtr, formatPtr, numItemsPtr, bytesAfterPtr, itemsPtr) \
(XGetWindowProperty((wrapperPtr)->display, (wrapperPtr)->window, \
(atom), 0, (long) (length), False, (type), \
(typePtr), (formatPtr), (numItemsPtr), (bytesAfterPtr), \
(unsigned char **) (itemsPtr)) == Success)
#define SetWindowProperty(wrapperPtr, atomName, type, width, data, length) \
XChangeProperty((wrapperPtr)->display, (wrapperPtr)->window, \
Tk_InternAtom((Tk_Window) wrapperPtr, (atomName)), \
(type), (width), PropModeReplace, (unsigned char *) (data), \
(int) (length))
/*
* This module keeps a list of all top-level windows, primarily to simplify
* the job of Tk_CoordsToWindow. The list is called firstWmPtr and is stored
* in the TkDisplay structure.
*/
/*
* The following structures are the official type records for geometry
* management of top-level and menubar windows.
*/
static void TopLevelReqProc(void *dummy, Tk_Window tkwin);
static void RemapWindows(TkWindow *winPtr, TkWindow *parentPtr);
static void MenubarReqProc(void *clientData,
Tk_Window tkwin);
static const Tk_GeomMgr wmMgrType = {
"wm", /* name */
TopLevelReqProc, /* requestProc */
NULL, /* lostContentProc */
};
static const Tk_GeomMgr menubarMgrType = {
"menubar", /* name */
MenubarReqProc, /* requestProc */
NULL, /* lostContentProc */
};
/*
* Structures of the following type are used for communication between
* WaitForEvent, WaitRestrictProc, and WaitTimeoutProc.
*/
typedef struct WaitRestrictInfo {
Display *display; /* Window belongs to this display. */
WmInfo *wmInfoPtr;
int type; /* We only care about this type of event. */
XEvent *eventPtr; /* Where to store the event when it's found. */
int foundEvent; /* Non-zero means that an event of the desired
* type has been found. */
} WaitRestrictInfo;
/*
* Forward declarations for functions defined in this file:
*/
static int ComputeReparentGeometry(WmInfo *wmPtr);
static void ConfigureEvent(WmInfo *wmPtr,
XConfigureEvent *eventPtr);
static void CreateWrapper(WmInfo *wmPtr);
static void GetMaxSize(WmInfo *wmPtr, int *maxWidthPtr,
int *maxHeightPtr);
static void MenubarDestroyProc(void *clientData,
XEvent *eventPtr);
static int ParseGeometry(Tcl_Interp *interp, const char *string,
TkWindow *winPtr);
static void ReparentEvent(WmInfo *wmPtr, XReparentEvent *eventPtr);
static void PropertyEvent(WmInfo *wmPtr, XPropertyEvent *eventPtr);
static void TkWmStackorderToplevelWrapperMap(TkWindow *winPtr,
Display *display, Tcl_HashTable *reparentTable);
static void TopLevelReqProc(void *dummy, Tk_Window tkwin);
static void RemapWindows(TkWindow *winPtr, TkWindow *parentPtr);
static void UpdateCommand(TkWindow *winPtr);
static void UpdateGeometryInfo(void *clientData);
static void UpdateHints(TkWindow *winPtr);
static void UpdateSizeHints(TkWindow *winPtr,
int newWidth, int newHeight);
static void UpdateTitle(TkWindow *winPtr);
static void UpdatePhotoIcon(TkWindow *winPtr);
static void UpdateVRootGeometry(WmInfo *wmPtr);
static void UpdateWmProtocols(WmInfo *wmPtr);
static int SetNetWmType(TkWindow *winPtr, Tcl_Obj *typePtr);
static Tcl_Obj * GetNetWmType(TkWindow *winPtr);
static void SetNetWmState(TkWindow*, const char *atomName, int on);
static void CheckNetWmState(WmInfo *, Atom *atoms, int numAtoms);
static void UpdateNetWmState(WmInfo *);
static void WaitForConfigureNotify(TkWindow *winPtr,
unsigned long serial);
static int WaitForEvent(Display *display,
WmInfo *wmInfoPtr, int type, XEvent *eventPtr);
static void WaitForMapNotify(TkWindow *winPtr, int mapped);
static Tk_RestrictProc WaitRestrictProc;
static void WrapperEventProc(void *clientData,
XEvent *eventPtr);
static void WmWaitMapProc(void *clientData,
XEvent *eventPtr);
static int WmAspectCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmAttributesCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmClientCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmColormapwindowsCmd(Tk_Window tkwin,
TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmCommandCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmDeiconifyCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmFocusmodelCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmForgetCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmFrameCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmGeometryCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmGridCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmGroupCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmIconbadgeCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmIconbitmapCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmIconifyCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmIconmaskCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmIconnameCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmIconphotoCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmIconpositionCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmIconwindowCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmManageCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmMaxsizeCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmMinsizeCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmOverrideredirectCmd(Tk_Window tkwin,
TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmPositionfromCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmProtocolCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmResizableCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmSizefromCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmStackorderCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmStateCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmTitleCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmTransientCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static int WmWithdrawCmd(Tk_Window tkwin, TkWindow *winPtr,
Tcl_Interp *interp, Tcl_Size objc,
Tcl_Obj *const objv[]);
static void WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr);
/*
*--------------------------------------------------------------
*
* TkWmCleanup --
*
* This function is invoked to cleanup remaining wm resources associated
* with a display.
*
* Results:
* None.
*
* Side effects:
* All WmInfo structure resources are freed and invalidated.
*
*--------------------------------------------------------------
*/
void TkWmCleanup(
TkDisplay *dispPtr)
{
WmInfo *wmPtr, *nextPtr;
for (wmPtr = dispPtr->firstWmPtr; wmPtr != NULL; wmPtr = nextPtr) {
/*
* We can't assume we have access to winPtr's anymore, so some cleanup
* requiring winPtr data is avoided.
*/
nextPtr = wmPtr->nextPtr;
if (wmPtr->title != NULL) {
ckfree(wmPtr->title);
}
if (wmPtr->iconName != NULL) {
ckfree(wmPtr->iconName);
}
if (wmPtr->iconDataPtr != NULL) {
ckfree(wmPtr->iconDataPtr);
}
if (wmPtr->leaderName != NULL) {
ckfree(wmPtr->leaderName);
}
if (wmPtr->menubar != NULL) {
Tk_DestroyWindow(wmPtr->menubar);
}
if (wmPtr->wrapperPtr != NULL) {
Tk_DestroyWindow((Tk_Window) wmPtr->wrapperPtr);
}
while (wmPtr->protPtr != NULL) {
ProtocolHandler *protPtr = wmPtr->protPtr;
wmPtr->protPtr = protPtr->nextPtr;
Tcl_EventuallyFree(protPtr, TCL_DYNAMIC);
}
if (wmPtr->cmdArgv != NULL) {
ckfree(wmPtr->cmdArgv);
}
if (wmPtr->clientMachine != NULL) {
ckfree(wmPtr->clientMachine);
}
ckfree(wmPtr);
}
if (dispPtr->iconDataPtr != NULL) {
ckfree(dispPtr->iconDataPtr);
dispPtr->iconDataPtr = NULL;
}
}
/*
*--------------------------------------------------------------
*
* TkWmNewWindow --
*
* This function is invoked whenever a new top-level window is created.
* Its job is to initialize the WmInfo structure for the window.
*
* Results:
* None.
*
* Side effects:
* A WmInfo structure gets allocated and initialized.
*
*--------------------------------------------------------------
*/
void
TkWmNewWindow(
TkWindow *winPtr) /* Newly-created top-level window. */
{
WmInfo *wmPtr;
TkDisplay *dispPtr = winPtr->dispPtr;
wmPtr = (WmInfo *)ckalloc(sizeof(WmInfo));
memset(wmPtr, 0, sizeof(WmInfo));
wmPtr->winPtr = winPtr;
wmPtr->reparent = None;
wmPtr->containerPtr = NULL;
wmPtr->numTransients = 0;
wmPtr->hints.flags = InputHint | StateHint;
wmPtr->hints.input = True;
wmPtr->hints.initial_state = NormalState;
wmPtr->hints.icon_pixmap = None;
wmPtr->hints.icon_window = None;
wmPtr->hints.icon_x = wmPtr->hints.icon_y = 0;
wmPtr->hints.icon_mask = None;
wmPtr->hints.window_group = None;
/*
* Initialize attributes.
*/
wmPtr->attributes.alpha = 1.0;
wmPtr->attributes.topmost = 0;
wmPtr->attributes.zoomed = 0;
wmPtr->attributes.fullscreen = 0;
wmPtr->reqState = wmPtr->attributes;
/*
* Default the maximum dimensions to the size of the display, minus a
* guess about how space is needed for window manager decorations.
*/
wmPtr->gridWin = NULL;
wmPtr->minWidth = wmPtr->minHeight = 1;
wmPtr->maxWidth = wmPtr->maxHeight = 0;
wmPtr->widthInc = wmPtr->heightInc = 1;
wmPtr->minAspect.x = wmPtr->minAspect.y = 1;
wmPtr->maxAspect.x = wmPtr->maxAspect.y = 1;
wmPtr->reqGridWidth = wmPtr->reqGridHeight = -1;
wmPtr->gravity = NorthWestGravity;
wmPtr->width = -1;
wmPtr->height = -1;
wmPtr->x = winPtr->changes.x;
wmPtr->y = winPtr->changes.y;
wmPtr->parentWidth = winPtr->changes.width
+ 2*winPtr->changes.border_width;
wmPtr->parentHeight = winPtr->changes.height
+ 2*winPtr->changes.border_width;
wmPtr->configWidth = -1;
wmPtr->configHeight = -1;
wmPtr->vRoot = None;
wmPtr->flags = WM_NEVER_MAPPED;
wmPtr->nextPtr = (WmInfo *) dispPtr->firstWmPtr;
dispPtr->firstWmPtr = wmPtr;
winPtr->wmInfoPtr = wmPtr;
UpdateVRootGeometry(wmPtr);
/*
* Arrange for geometry requests to be reflected from the window to the
* window manager.
*/
Tk_ManageGeometry((Tk_Window) winPtr, &wmMgrType, NULL);
}
/*
*--------------------------------------------------------------
*
* TkWmMapWindow --
*
* This function is invoked to map a top-level window. This module gets a
* chance to update all window-manager-related information in properties
* before the window manager sees the map event and checks the
* properties. It also gets to decide whether or not to even map the
* window after all.
*
* Results:
* None.
*
* Side effects:
* Properties of winPtr may get updated to provide up-to-date information
* to the window manager. The window may also get mapped, but it may not
* be if this function decides that isn't appropriate (e.g. because the
* window is withdrawn).
*
*--------------------------------------------------------------
*/
void
TkWmMapWindow(
TkWindow *winPtr) /* Top-level window that's about to be
* mapped. */
{
WmInfo *wmPtr = winPtr->wmInfoPtr;
XTextProperty textProp;
if (wmPtr->flags & WM_NEVER_MAPPED) {
Tcl_DString ds;
wmPtr->flags &= ~WM_NEVER_MAPPED;
/*
* This is the first time this window has ever been mapped. First
* create the wrapper window that provides space for a menubar.
*/
if (wmPtr->wrapperPtr == NULL) {
CreateWrapper(wmPtr);
}
/*
* Store all the window-manager-related information for the window.
*/
TkWmSetClass(winPtr);
UpdateTitle(winPtr);
UpdatePhotoIcon(winPtr);
if (wmPtr->containerPtr != NULL) {
/*
* Don't map a transient if the container is not mapped.
*/
if (!Tk_IsMapped(wmPtr->containerPtr)) {
wmPtr->withdrawn = 1;
wmPtr->hints.initial_state = WithdrawnState;
}
/*
* Make sure that we actually set the transient-for property, even
* if we are withdrawn. [Bug 1163496]
*/
XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
wmPtr->containerPtr->wmInfoPtr->wrapperPtr->window);
}
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
UpdateHints(winPtr);
UpdateWmProtocols(wmPtr);
if (wmPtr->cmdArgv != NULL) {
UpdateCommand(winPtr);
}
if (wmPtr->clientMachine != NULL) {
(void)Tcl_UtfToExternalDString(NULL, wmPtr->clientMachine, TCL_INDEX_NONE, &ds);
if (XStringListToTextProperty(&(Tcl_DStringValue(&ds)), 1,
&textProp) != 0) {
unsigned long pid = (unsigned long) getpid();
XSetWMClientMachine(winPtr->display,
wmPtr->wrapperPtr->window, &textProp);
XFree(textProp.value);
/*
* Inform the server (and more particularly any session
* manager) what our process ID is. We only do this when the
* CLIENT_MACHINE property is set since the spec for
* _NET_WM_PID requires that to be set too.
*/
SetWindowProperty(wmPtr->wrapperPtr, "_NET_WM_PID",
XA_CARDINAL, 32, &pid, 1);
}
Tcl_DStringFree(&ds);
}
}
if (wmPtr->hints.initial_state == WithdrawnState) {
return;
}
if (wmPtr->iconFor != NULL) {
/*
* This window is an icon for somebody else. Make sure that the
* geometry is up-to-date, then return without mapping the window.
*/
if (wmPtr->flags & WM_UPDATE_PENDING) {
Tcl_CancelIdleCall(UpdateGeometryInfo, winPtr);
}
UpdateGeometryInfo(winPtr);
return;
}
wmPtr->flags |= WM_ABOUT_TO_MAP;
if (wmPtr->flags & WM_UPDATE_PENDING) {
Tcl_CancelIdleCall(UpdateGeometryInfo, winPtr);
}
UpdateGeometryInfo(winPtr);
wmPtr->flags &= ~WM_ABOUT_TO_MAP;
/*
* Update _NET_WM_STATE hints:
*/
UpdateNetWmState(wmPtr);
/*
* Map the window, then wait to be sure that the window manager has
* processed the map operation.
*/
XMapWindow(winPtr->display, wmPtr->wrapperPtr->window);
if (wmPtr->hints.initial_state == NormalState) {
WaitForMapNotify(winPtr, 1);
}
}
/*
*--------------------------------------------------------------
*
* TkWmUnmapWindow --
*
* This function is invoked to unmap a top-level window. The only thing
* it does special is to wait for the window actually to be unmapped.
*
* Results:
* None.
*
* Side effects:
* Unmaps the window.
*
*--------------------------------------------------------------
*/
void
TkWmUnmapWindow(
TkWindow *winPtr) /* Top-level window that's about to be
* mapped. */
{
/*
* It seems to be important to wait after unmapping a top-level window
* until the window really gets unmapped. I don't completely understand
* all the interactions with the window manager, but if we go on without
* waiting, and if the window is then mapped again quickly, events seem to
* get lost so that we think the window isn't mapped when in fact it is
* mapped. I suspect that this has something to do with the window manager
* filtering Map events (and possily not filtering Unmap events?).
*/
XUnmapWindow(winPtr->display, winPtr->wmInfoPtr->wrapperPtr->window);
WaitForMapNotify(winPtr, 0);
}
/*
*--------------------------------------------------------------
*
* TkWmDeadWindow --
*
* This function is invoked when a top-level window is about to be
* deleted. It cleans up the wm-related data structures for the window.
*
* Results:
* None.
*
* Side effects:
* The WmInfo structure for winPtr gets freed up.
*
*--------------------------------------------------------------
*/
void
TkWmDeadWindow(
TkWindow *winPtr) /* Top-level window that's being deleted. */
{
WmInfo *wmPtr = winPtr->wmInfoPtr;
WmInfo *wmPtr2;
if (wmPtr == NULL) {
return;
}
if ((WmInfo *) winPtr->dispPtr->firstWmPtr == wmPtr) {
winPtr->dispPtr->firstWmPtr = wmPtr->nextPtr;
} else {
WmInfo *prevPtr;
for (prevPtr = (WmInfo *) winPtr->dispPtr->firstWmPtr; ;
prevPtr = prevPtr->nextPtr) {
/* ASSERT: prevPtr != NULL [Bug 1789819] */
if (prevPtr->nextPtr == wmPtr) {
prevPtr->nextPtr = wmPtr->nextPtr;
break;
}
}
}
if (wmPtr->title != NULL) {
ckfree(wmPtr->title);
}
if (wmPtr->iconName != NULL) {
ckfree(wmPtr->iconName);
}
if (wmPtr->iconDataPtr != NULL) {
ckfree(wmPtr->iconDataPtr);
}
if (wmPtr->hints.flags & IconPixmapHint) {
Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
}
if (wmPtr->hints.flags & IconMaskHint) {
Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_mask);
}
if (wmPtr->leaderName != NULL) {
ckfree(wmPtr->leaderName);
}
if (wmPtr->icon != NULL) {
wmPtr2 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
wmPtr2->iconFor = NULL;
wmPtr2->withdrawn = 1;
}
if (wmPtr->iconFor != NULL) {
wmPtr2 = ((TkWindow *) wmPtr->iconFor)->wmInfoPtr;
wmPtr2->icon = NULL;
wmPtr2->hints.flags &= ~IconWindowHint;
UpdateHints((TkWindow *) wmPtr->iconFor);
}
if (wmPtr->menubar != NULL) {
Tk_DestroyWindow(wmPtr->menubar);
}
if (wmPtr->wrapperPtr != NULL) {
/*
* The rest of Tk doesn't know that we reparent the toplevel inside
* the wrapper, so reparent it back out again before deleting the
* wrapper; otherwise the toplevel will get deleted twice (once
* implicitly by the deletion of the wrapper).
*/
XUnmapWindow(winPtr->display, winPtr->window);
XReparentWindow(winPtr->display, winPtr->window,
XRootWindow(winPtr->display, winPtr->screenNum), 0, 0);
Tk_DestroyWindow((Tk_Window) wmPtr->wrapperPtr);
}
while (wmPtr->protPtr != NULL) {
ProtocolHandler *protPtr = wmPtr->protPtr;
wmPtr->protPtr = protPtr->nextPtr;
Tcl_EventuallyFree(protPtr, TCL_DYNAMIC);
}
if (wmPtr->cmdArgv != NULL) {
ckfree(wmPtr->cmdArgv);
}
if (wmPtr->clientMachine != NULL) {
ckfree(wmPtr->clientMachine);
}
if (wmPtr->flags & WM_UPDATE_PENDING) {
Tcl_CancelIdleCall(UpdateGeometryInfo, winPtr);
}
/*
* Reset all transient windows whose container is the dead window.
*/
for (wmPtr2 = winPtr->dispPtr->firstWmPtr; wmPtr2 != NULL;
wmPtr2 = wmPtr2->nextPtr) {
if (wmPtr2->containerPtr == winPtr) {
wmPtr->numTransients--;
Tk_DeleteEventHandler((Tk_Window) wmPtr2->containerPtr,
StructureNotifyMask, WmWaitMapProc, wmPtr2->winPtr);
wmPtr2->containerPtr = NULL;
if (!(wmPtr2->flags & WM_NEVER_MAPPED)) {
XDeleteProperty(winPtr->display, wmPtr2->wrapperPtr->window,
Tk_InternAtom((Tk_Window) winPtr, "WM_TRANSIENT_FOR"));
/*
* FIXME: Need a call like Win32's UpdateWrapper() so we can
* recreate the wrapper and get rid of the transient window
* decorations.
*/
}
}
}
/* ASSERT: numTransients == 0 [Bug 1789819] */
if (wmPtr->containerPtr != NULL) {
wmPtr2 = wmPtr->containerPtr->wmInfoPtr;
/*
* If we had a container, tell them that we aren't tied to them anymore
*/
if (wmPtr2 != NULL) {
wmPtr2->numTransients--;
}
Tk_DeleteEventHandler((Tk_Window) wmPtr->containerPtr,
StructureNotifyMask, WmWaitMapProc, winPtr);
wmPtr->containerPtr = NULL;
}
ckfree(wmPtr);
winPtr->wmInfoPtr = NULL;
}
/*
*--------------------------------------------------------------
*
* TkWmSetClass --
*
* This function is invoked whenever a top-level window's class is
* changed. If the window has been mapped then this function updates the
* window manager property for the class. If the window hasn't been
* mapped, the update is deferred until just before the first mapping.
*
* Results:
* None.
*
* Side effects:
* A window property may get updated.
*
*--------------------------------------------------------------
*/
void
TkWmSetClass(
TkWindow *winPtr) /* Newly-created top-level window. */
{
if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
return;
}
if (winPtr->classUid != NULL) {
XClassHint *classPtr;
Tcl_DString name, ds;
(void)Tcl_UtfToExternalDString(NULL, winPtr->nameUid, TCL_INDEX_NONE, &name);
(void)Tcl_UtfToExternalDString(NULL, winPtr->classUid, TCL_INDEX_NONE, &ds);
classPtr = XAllocClassHint();
classPtr->res_name = Tcl_DStringValue(&name);
classPtr->res_class = Tcl_DStringValue(&ds);
XSetClassHint(winPtr->display, winPtr->wmInfoPtr->wrapperPtr->window,
classPtr);
XFree(classPtr);
Tcl_DStringFree(&name);
Tcl_DStringFree(&ds);
}
}