-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_window.c
2375 lines (2006 loc) · 66 KB
/
add_window.c
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
/*****************************************************************************/
/** Copyright 1988 by Evans & Sutherland Computer Corporation, **/
/** Salt Lake City, Utah **/
/** Portions Copyright 1989 by the Massachusetts Institute of Technology **/
/** Cambridge, Massachusetts **/
/** **/
/** All Rights Reserved **/
/** **/
/** Permission to use, copy, modify, and distribute this software and **/
/** its documentation for any purpose and without fee is hereby **/
/** granted, provided that the above copyright notice appear in all **/
/** copies and that both that copyright notice and this permis- **/
/** sion notice appear in supporting documentation, and that the **/
/** names of Evans & Sutherland and M.I.T. not be used in advertising **/
/** in publicity pertaining to distribution of the software without **/
/** specific, written prior permission. **/
/** **/
/** EVANS & SUTHERLAND AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD **/
/** TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- **/
/** ABILITY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND OR **/
/** M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAM- **/
/** AGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/
/** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/
/** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/
/** OR PERFORMANCE OF THIS SOFTWARE. **/
/*****************************************************************************/
/**********************************************************************
*
* $XConsortium: add_window.c,v 1.153 91/07/10 13:17:26 dave Exp $
*
* Add a new window, put the titlbar and other stuff around
* the window
*
* 31-Mar-88 Tom LaStrange Initial Version.
*
**********************************************************************/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "twm.h"
#include <X11/Xatom.h>
#ifndef NO_XPM_SUPPORT
#include <X11/xpm.h>
#endif
#include "add_window.h"
#include "image_formats.h"
#include "util.h"
#include "resize.h"
#include "parse.h"
#include "gram.h"
#include "list.h"
#include "events.h"
#include "menus.h"
#include "screen.h"
#include "iconmgr.h"
#include "desktop.h"
#include "prototypes.h"
/* random placement coordinates */
#define PLACEMENT_START 50
#define PLACEMENT_INCR 30
static void AddMoveAndResize(TwmWindow * tmp_win, int ask_user);
static void CreateWindowTitlebarButtons(TwmWindow * tmp_win);
#define gray_width 2
#define gray_height 2
static char gray_bits[] = {
0x02, 0x01
};
static unsigned char black_bits[] = {
0xFF, 0xFF
};
int AddingX;
int AddingY;
int AddingW;
int AddingH;
char NoName[] = "Untitled"; /* name if no name is specified */
/************************************************************************
*
* Procedure:
* GetGravityOffsets - map gravity to (x,y) offset signs for adding
* to x and y when window is mapped to get proper placement.
*
************************************************************************
*/
void
GetGravityOffsets(TwmWindow * tmp, /* window from which to get gravity */
int *xp, int *yp /* return values */
)
{
static struct _gravity_offset
{
int x, y;
} gravity_offsets[11] =
{
{
0, 0}, /* ForgetGravity */
{
-1, -1}, /* NorthWestGravity */
{
0, -1}, /* NorthGravity */
{
1, -1}, /* NorthEastGravity */
{
-1, 0}, /* WestGravity */
{
0, 0}, /* CenterGravity */
{
1, 0}, /* EastGravity */
{
-1, 1}, /* SouthWestGravity */
{
0, 1}, /* SouthGravity */
{
1, 1}, /* SouthEastGravity */
{
0, 0}, /* StaticGravity */
};
register int g = ((tmp->hints.flags & PWinGravity) ? tmp->hints.win_gravity : NorthWestGravity);
if (g < ForgetGravity || g > StaticGravity)
{
*xp = *yp = 0;
}
else
{
*xp = gravity_offsets[g].x;
*yp = gravity_offsets[g].y;
}
}
/*
* From vtwm.c win_utils.c (thanks to Matthew Fuller)
*
* Create synthetic WM_HINTS info for windows. When a window specifies
* stuff, we should probably pay attention to it (though we don't
* always; x-ref comments in AddWindow() especially about focus).
* However, when it doesn't tell us anything at all, we should assume
* something useful. "Window managers are free to assume convenient
* values for all fields of the WM_HINTS property if a window is mapped
* without one." (ICCCM Ch. 4,
* <https://www.x.org/releases/X11R7.7/doc/xorg-docs/icccm/icccm.html#Client_Properties>).
*
* Specifically, we assume it wants us to give it focus. It's fairly
* bogus for a window not to tell us anything, but e.g current versions
* of Chrome do (don't do) just that. So we better make up something
* useful.
*
* Should probably be some configurability for this, so make the func
* take the window, even though we don't currently do anything useful
* with it...
*/
XWMHints *
gen_synthetic_wmhints(void)
{
XWMHints *hints;
hints = XAllocWMHints();
if(!hints) {
return NULL;
}
/*
* Reasonable defaults. Takes input, in normal state.
*
* XXX Make configurable?
*/
hints->flags = InputHint | StateHint;
hints->input = True;
hints->initial_state = NormalState;
return hints;
}
/***********************************************************************
*
* Procedure:
* AddWindow - add a new window to the twm list
*
* Returned Value:
* (TwmWindow *) - pointer to the TwmWindow structure
*
* Inputs:
* w - the window id of the window to add
* iconm - flag to tell if this is an icon manager window
* iconp - pointer to icon manager struct
*
***********************************************************************
*/
TwmWindow *
AddWindow(Window w, int iconm, IconMgr * iconp)
{
TwmWindow *tmp_win; /* new twm window structure */
TwmWindow **ptmp_win;
unsigned long valuemask; /* mask for create windows */
XSetWindowAttributes attributes; /* attributes for create windows */
Atom actual_type;
int actual_format;
unsigned long nitems, bytesafter;
int ask_user; /* don't know where to put the window */
int *ppos_ptr, ppos_on;
int gravx, gravy; /* gravity signs for positioning */
int namelen;
int bw2;
char *icon_name;
char *name;
Atom motifhints = XInternAtom(dpy, "_MOTIF_WM_HINTS", 0);
MotifWmHints *mwmhints;
#ifdef DEBUG
fprintf(stderr, "AddWindow: w = 0x%x\n", w);
#endif
/* allocate space for the twm window */
tmp_win = (TwmWindow *) calloc(1, sizeof(TwmWindow));
if (tmp_win == 0)
{
fprintf(stderr, "%s: Unable to allocate memory to manage window ID %lx.\n", ProgramName, w);
return NULL;
}
tmp_win->w = w;
tmp_win->zoomed = ZOOM_NONE;
tmp_win->iconmgr = iconm;
tmp_win->iconmgrp = iconp;
tmp_win->cmaps.number_cwins = 0;
XSelectInput(dpy, tmp_win->w, PropertyChangeMask);
XGetWindowAttributes(dpy, tmp_win->w, &tmp_win->attr);
if (I18N_FetchName(dpy, tmp_win->w, &name))
{
tmp_win->name = strdup(name);
free(name);
}
else
tmp_win->name = NoName;
tmp_win->class = NoClass;
XGetClassHint(dpy, tmp_win->w, &tmp_win->class);
FetchWmProtocols(tmp_win);
FetchWmColormapWindows(tmp_win);
/*
* do initial clip; should look at window gravity
*/
if (tmp_win->attr.width > Scr->MaxWindowWidth)
tmp_win->attr.width = Scr->MaxWindowWidth;
if (tmp_win->attr.height > Scr->MaxWindowHeight)
tmp_win->attr.height = Scr->MaxWindowHeight;
tmp_win->wmhints = XGetWMHints(dpy, tmp_win->w);
if (!tmp_win->wmhints)
tmp_win->wmhints = gen_synthetic_wmhints();
if (tmp_win->wmhints && (tmp_win->wmhints->flags & WindowGroupHint))
tmp_win->group = tmp_win->wmhints->window_group;
else
tmp_win->group = tmp_win->w;
tmp_win->mwmhints.flags = 0;
if (motifhints != None)
{
if (XGetWindowProperty(dpy, tmp_win->w, motifhints,
0L, sizeof(MotifWmHints), False,
motifhints, &actual_type, &actual_format,
&nitems, &bytesafter, (unsigned char **)&mwmhints) == Success && actual_type != None)
{
if (mwmhints)
{
tmp_win->mwmhints = *mwmhints;
XFree(mwmhints);
}
}
}
/*
* The July 27, 1988 draft of the ICCCM ignores the size and position
* fields in the WM_NORMAL_HINTS property.
*/
tmp_win->transient = Transient(tmp_win->w, &tmp_win->transientfor);
if (tmp_win->class.res_name == NULL)
tmp_win->class.res_name = NoName;
if (tmp_win->class.res_class == NULL)
tmp_win->class.res_class = NoName;
tmp_win->full_name = tmp_win->name;
namelen = strlen(tmp_win->name);
tmp_win->highlight = Scr->Highlight && (LookInList(Scr->NoHighlight, tmp_win->full_name, &tmp_win->class) == (char *)NULL);
tmp_win->stackmode = Scr->StackMode && (LookInList(Scr->NoStackModeL, tmp_win->full_name, &tmp_win->class) == (char *)NULL);
tmp_win->titlehighlight = Scr->TitleHighlight &&
(LookInList(Scr->NoTitleHighlight, tmp_win->full_name, &tmp_win->class) == (char *)NULL);
tmp_win->auto_raise = Scr->AutoRaiseDefault || (LookInList(Scr->AutoRaise, tmp_win->full_name, &tmp_win->class) != (char *)NULL);
if (tmp_win->auto_raise)
Scr->NumAutoRaises++;
tmp_win->iconify_by_unmapping = Scr->IconifyByUnmapping;
if (Scr->IconifyByUnmapping)
{
tmp_win->iconify_by_unmapping = (LookInList(Scr->DontIconify, tmp_win->full_name, &tmp_win->class) == (char *)NULL);
}
tmp_win->iconify_by_unmapping |= (LookInList(Scr->IconifyByUn, tmp_win->full_name, &tmp_win->class) != (char *)NULL);
if (LookInList(Scr->NailedDown, tmp_win->full_name, &tmp_win->class))
tmp_win->nailed = TRUE;
else
tmp_win->nailed = FALSE;
if (LookInList(Scr->DontShowInDisplay, tmp_win->full_name, &tmp_win->class))
tmp_win->showindesktopdisplay = FALSE;
else
tmp_win->showindesktopdisplay = TRUE;
if (LookInList(Scr->Immutable, tmp_win->full_name, &tmp_win->class)) {
tmp_win->immutable = TRUE;
} else {
tmp_win->immutable = FALSE;
}
tmp_win->squeeze_info = NULL;
/*
* get the squeeze information; note that this does not have to be freed
* since it is coming from the screen list
*/
if (HasShape)
{
if (!LookInList(Scr->DontSqueezeTitleL, tmp_win->full_name, &tmp_win->class))
{
tmp_win->squeeze_info = (SqueezeInfo *) LookInList(Scr->SqueezeTitleL, tmp_win->full_name, &tmp_win->class);
if (!tmp_win->squeeze_info)
{
static SqueezeInfo default_squeeze = { J_LEFT, 0, 0 };
if (Scr->SqueezeTitle)
tmp_win->squeeze_info = &default_squeeze;
}
}
}
tmp_win->old_bw = tmp_win->attr.border_width;
if (Scr->NoBorders || LookInList(Scr->NoBorder, tmp_win->full_name, &tmp_win->class))
{
tmp_win->frame_bw = 0;
tmp_win->frame_bw3D = 0;
}
else
{
if (Scr->BorderBevelWidth > 0)
{
tmp_win->frame_bw3D = Scr->BorderWidth;
tmp_win->frame_bw = 0;
Scr->ClientBorderWidth = FALSE;
}
else
{
tmp_win->frame_bw3D = 0;
if (Scr->ClientBorderWidth)
tmp_win->frame_bw = tmp_win->old_bw;
else
tmp_win->frame_bw = Scr->BorderWidth;
}
}
if (tmp_win->mwmhints.flags & MWM_HINTS_DECORATIONS)
{
if (tmp_win->mwmhints.decorations & MWM_DECOR_ALL)
tmp_win->mwmhints.decorations |= (MWM_DECOR_BORDER |
MWM_DECOR_RESIZEH | MWM_DECOR_TITLE |
MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE);
if (!(tmp_win->mwmhints.decorations & MWM_DECOR_BORDER))
tmp_win->frame_bw = tmp_win->frame_bw3D = 0;
}
if (tmp_win->mwmhints.flags & MWM_HINTS_FUNCTIONS)
if (tmp_win->mwmhints.functions & MWM_FUNC_ALL)
tmp_win->mwmhints.functions |= (MWM_FUNC_RESIZE | MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_CLOSE);
bw2 = tmp_win->frame_bw * 2;
tmp_win->title_height = Scr->TitleHeight + tmp_win->frame_bw;
if (tmp_win->mwmhints.flags & MWM_HINTS_DECORATIONS && !(tmp_win->mwmhints.decorations & MWM_DECOR_TITLE))
tmp_win->title_height = 0;
if (Scr->NoTitlebar)
tmp_win->title_height = 0;
if (LookInList(Scr->NoTitle, tmp_win->full_name, &tmp_win->class))
tmp_win->title_height = 0;
if (LookInList(Scr->MakeTitle, tmp_win->full_name, &tmp_win->class))
tmp_win->title_height = Scr->TitleHeight + tmp_win->frame_bw;
if (LookInList(Scr->OpaqueMoveL, tmp_win->full_name, &tmp_win->class))
tmp_win->opaque_move = TRUE;
else
tmp_win->opaque_move = Scr->OpaqueMove && (LookInList(Scr->NoOpaqueMoveL, tmp_win->full_name, &tmp_win->class) == (char *)NULL);
if (tmp_win->opaque_move)
tmp_win->attr.save_under = True;
if (LookInList(Scr->OpaqueResizeL, tmp_win->full_name, &tmp_win->class))
tmp_win->opaque_resize = TRUE;
else
tmp_win->opaque_resize = Scr->OpaqueResize &&
(LookInList(Scr->NoOpaqueResizeL, tmp_win->full_name, &tmp_win->class) == (char *)NULL);
if (tmp_win->opaque_resize)
tmp_win->attr.save_under = True;
/* if it is a transient window, don't put a title on it */
if (tmp_win->transient && !Scr->DecorateTransients)
tmp_win->title_height = 0;
if (LookInList(Scr->StartIconified, tmp_win->full_name, &tmp_win->class))
{
if (!tmp_win->wmhints)
tmp_win->wmhints = XAllocWMHints();
tmp_win->wmhints->initial_state = IconicState;
tmp_win->wmhints->flags |= StateHint;
}
GetWindowSizeHints(tmp_win);
GetGravityOffsets(tmp_win, &gravx, &gravy);
/*
* Bug 3065630 -- If we have a recent window from the same group and
* we don't have anyplace to put it pick the same place as the last
* window (e.g. storm positioning)
*/
#ifdef DEBUG
fprintf(stderr,"Spawning window %x in group %x with hints %x(%d)\n",tmp_win->w,tmp_win->group,tmp_win->hints.flags,(tmp_win->hints.flags & USPosition));
#endif
if (Scr->StormPositioning && HandlingEvents == TRUE &&
!(tmp_win->hints.flags & USPosition) && (tmp_win->group != tmp_win->w))
{
static int lastwingroup = 0;
static int lastwin = 0;
static int lasttime = 0;
int curtime = time(NULL);
Window junk;
if ((lastwingroup == tmp_win->group) && ((curtime-15) < lasttime) &&
(XTranslateCoordinates(dpy, lastwin, Scr->Root, 0, 0, &JunkX, &JunkY, &junk) == True) &&
JunkX >= 0 && JunkY >= 0)
{
tmp_win->attr.x = JunkX;
tmp_win->attr.y = JunkY;
if (Scr->GeometriesAreVirtual &&
tmp_win->attr.x < Scr->MyDisplayWidth && tmp_win->attr.y < Scr->MyDisplayHeight)
{
tmp_win->attr.x = R_TO_V_X(tmp_win->attr.x);
tmp_win->attr.y = R_TO_V_Y(tmp_win->attr.y);
}
/*
* Note that apparently we have to adjust this by 2x the boarder for true overlap.
* But...I like the subtle visual notice that we have multiple windows stacked and
* the adjustment is minor enough that you generally will not need to move the mouse
* when you are dismissing the windows.
*/
tmp_win->attr.x -= tmp_win->frame_bw + tmp_win->frame_bw3D;
tmp_win->attr.y -= tmp_win->title_height + tmp_win->frame_bw + tmp_win->frame_bw3D;
tmp_win->hints.flags |= USPosition;
tmp_win->hints.flags &= !PPosition;
}
lastwingroup = tmp_win->group;
lastwin = tmp_win->w;
lasttime = curtime;
}
/*
* Don't bother user if:
*
* o the window is a transient, or
*
* o a USPosition was requested, or
*
* o a PPosition was requested and UsePPosition is ON or
* NON_ZERO if the window is at other than (0,0)
*/
if ((ppos_ptr = (int *)LookInList(Scr->UsePPositionL, tmp_win->full_name, &tmp_win->class)))
ppos_on = *ppos_ptr;
else
ppos_on = Scr->UsePPosition;
if (ppos_on == PPOS_NON_ZERO && (tmp_win->attr.x != 0 || tmp_win->attr.y != 0))
ppos_on = PPOS_ON;
ask_user = TRUE;
if (tmp_win->transient || (tmp_win->hints.flags & USPosition) || ((tmp_win->hints.flags & PPosition) && ppos_on == PPOS_ON))
ask_user = FALSE;
/* check for applet regions - djhjr - 4/26/99 */
if (PlaceApplet(tmp_win, tmp_win->attr.x, tmp_win->attr.y, &tmp_win->attr.x, &tmp_win->attr.y))
ask_user = FALSE;
/* If we want the window to appear on-screen and it is off, ask the user/use random */
if (ppos_on == PPOS_ON_SCREEN &&
(tmp_win->attr.x < Scr->VirtualDesktopX ||
tmp_win->attr.x >= Scr->VirtualDesktopX + Scr->MyDisplayWidth ||
tmp_win->attr.y < Scr->VirtualDesktopY || tmp_win->attr.y >= Scr->VirtualDesktopY + Scr->MyDisplayHeight))
ask_user = TRUE;
if (LookInList(Scr->NailedDown, tmp_win->full_name, &tmp_win->class))
tmp_win->nailed = TRUE;
else
tmp_win->nailed = FALSE;
/*
* 25/09/90 - Nailed windows should always be on the real screen,
* regardless of PPosition or UPosition. If we are dealing with
* PPosition, then offset by the current real screen offset on the vd.
*/
if (tmp_win->nailed || ((tmp_win->hints.flags & PPosition) && (ask_user == FALSE)))
{
tmp_win->attr.x = R_TO_V_X(tmp_win->attr.x);
tmp_win->attr.y = R_TO_V_Y(tmp_win->attr.y);
}
if (!Scr->ClientBorderWidth)
{ /* need to adjust for twm borders */
int delta = -(tmp_win->frame_bw + tmp_win->frame_bw3D);
tmp_win->attr.x += gravx * delta;
tmp_win->attr.y += gravy * delta;
}
/*
* For windows with specified non-northwest gravities.
*/
if (tmp_win->old_bw)
{
if (!Scr->ClientBorderWidth)
{
JunkX = gravx + 1;
JunkY = gravy + 1;
}
else
JunkX = JunkY = 1;
tmp_win->attr.x += JunkX * tmp_win->old_bw;
tmp_win->attr.y += JunkY * tmp_win->old_bw;
}
tmp_win->title_width = tmp_win->attr.width;
if (tmp_win->old_bw)
XSetWindowBorderWidth(dpy, tmp_win->w, 0);
tmp_win->name_width = MyFont_TextWidth(&Scr->TitleBarFont, tmp_win->name, namelen);
if (I18N_GetIconName(dpy, tmp_win->w, &icon_name))
{
tmp_win->icon_name = strdup(icon_name);
free(icon_name);
}
else
tmp_win->icon_name = strdup(tmp_win->name);
tmp_win->iconified = FALSE;
tmp_win->icon = FALSE;
tmp_win->icon_on = FALSE;
XGrabServer(dpy);
/*
* Make sure the client window still exists. We don't want to leave an
* orphan frame window if it doesn't. Since we now have the server
* grabbed, the window can't disappear later without having been
* reparented, so we'll get a DestroyNotify for it. We won't have
* gotten one for anything up to here, however.
*/
if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0)
{
/*
* Allocated are full_name, name, icon_name, wmhints, res_name/-class, cwins.
* (See also HandleDestroyNotify().)
*/
free_window_names (tmp_win, True, True, True); /* 1, 2, 3 */
if (tmp_win->wmhints) /* 4 */
XFree ((char *)tmp_win->wmhints);
if (tmp_win->class.res_name && tmp_win->class.res_name != NoName) /* 5 */
XFree ((char *)tmp_win->class.res_name);
if (tmp_win->class.res_class && tmp_win->class.res_class != NoName) /* 6 */
XFree ((char *)tmp_win->class.res_class);
free_cwins (tmp_win); /* 9 */
free((char *)tmp_win);
XUngrabServer(dpy);
return (NULL);
}
/* _append_ the window into the twm list (simplify 'group leader' search) */
tmp_win->next = NULL;
tmp_win->prev = &Scr->TwmRoot;
ptmp_win = &Scr->TwmRoot.next;
while (*ptmp_win)
{
tmp_win->prev = (*ptmp_win);
ptmp_win = &((*ptmp_win)->next);
}
(*ptmp_win) = tmp_win;
if ((Scr->UseWindowRing ||
LookInList(Scr->WindowRingL, tmp_win->full_name,
&tmp_win->class)) && LookInList(Scr->NoWindowRingL, tmp_win->full_name, &tmp_win->class) == (char *)NULL)
{
AddWindowToRing(tmp_win);
}
else
tmp_win->ring.next = tmp_win->ring.prev = NULL;
/* get all the colors for the window */
tmp_win->border.back = Scr->BorderColor;
tmp_win->icon_border = Scr->IconBorderColor;
tmp_win->border_tile.fore = Scr->BorderTileC.fore;
tmp_win->border_tile.back = Scr->BorderTileC.back;
tmp_win->title.fore = Scr->TitleC.fore;
tmp_win->title.back = Scr->TitleC.back;
tmp_win->iconc.fore = Scr->IconC.fore;
tmp_win->iconc.back = Scr->IconC.back;
tmp_win->virtual.fore = Scr->VirtualDesktopDisplayC.fore;
tmp_win->virtual.back = Scr->VirtualDesktopDisplayC.back;
GetColorFromList(Scr->BorderColorL, tmp_win->full_name, &tmp_win->class, &tmp_win->border.back);
GetColorFromList(Scr->IconBorderColorL, tmp_win->full_name, &tmp_win->class, &tmp_win->icon_border);
GetColorFromList(Scr->BorderTileForegroundL, tmp_win->full_name, &tmp_win->class, &tmp_win->border_tile.fore);
GetColorFromList(Scr->BorderTileBackgroundL, tmp_win->full_name, &tmp_win->class, &tmp_win->border_tile.back);
GetColorFromList(Scr->TitleForegroundL, tmp_win->full_name, &tmp_win->class, &tmp_win->title.fore);
GetColorFromList(Scr->TitleBackgroundL, tmp_win->full_name, &tmp_win->class, &tmp_win->title.back);
GetColorFromList(Scr->IconForegroundL, tmp_win->full_name, &tmp_win->class, &tmp_win->iconc.fore);
GetColorFromList(Scr->IconBackgroundL, tmp_win->full_name, &tmp_win->class, &tmp_win->iconc.back);
/* fixed transposed fallback fore and back color lists - djhjr - 9/25/01 */
if (!GetColorFromList(Scr->VirtualDesktopColorFL, tmp_win->full_name, &tmp_win->class, &tmp_win->virtual.fore))
GetColorFromList(Scr->TitleForegroundL, tmp_win->full_name, &tmp_win->class, &tmp_win->virtual.fore);
if (!GetColorFromList(Scr->VirtualDesktopColorBL, tmp_win->full_name, &tmp_win->class, &tmp_win->virtual.back))
GetColorFromList(Scr->TitleBackgroundL, tmp_win->full_name, &tmp_win->class, &tmp_win->virtual.back);
if (!Scr->BeNiceToColormap)
GetShadeColors(&tmp_win->title);
if ((Scr->ButtonColorIsFrame || Scr->BorderBevelWidth > 0) && !Scr->BeNiceToColormap)
{
GetShadeColors(&tmp_win->border);
GetShadeColors(&tmp_win->border_tile);
}
#ifdef TWM_USE_XFT
if (Scr->use_xft > 0)
{
CopyPixelToXftColor(tmp_win->title.fore, &tmp_win->title.xft);
CopyPixelToXftColor(tmp_win->iconc.fore, &tmp_win->iconc.xft);
CopyPixelToXftColor(tmp_win->virtual.fore, &tmp_win->virtual.xft);
}
#endif
/* create windows */
tmp_win->frame_width = tmp_win->attr.width + 2 * tmp_win->frame_bw3D;
tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height + 2 * tmp_win->frame_bw3D;
valuemask = CWBorderPixel | CWCursor | CWEventMask | CWBackPixel;
attributes.background_pixel = tmp_win->border.back;
attributes.border_pixel = tmp_win->border.back;
attributes.cursor = Scr->FrameCursor;
attributes.event_mask = (SubstructureRedirectMask |
ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | ExposureMask);
if (tmp_win->attr.save_under)
{
attributes.save_under = True;
valuemask |= CWSaveUnder;
}
if (tmp_win->hints.flags & PWinGravity)
{
attributes.win_gravity = tmp_win->hints.win_gravity;
valuemask |= CWWinGravity;
}
tmp_win->frame = XCreateWindow(dpy, Scr->Root, tmp_win->frame_x,
tmp_win->frame_y,
(unsigned int)tmp_win->frame_width,
(unsigned int)tmp_win->frame_height,
(unsigned int)tmp_win->frame_bw,
Scr->d_depth, (unsigned int)CopyFromParent, Scr->d_visual, valuemask, &attributes);
#ifdef TWM_USE_OPACITY
PropagateWindowOpacity(tmp_win);
#endif
if (tmp_win->title_height)
{
valuemask = (CWEventMask | CWBorderPixel | CWBackPixel);
attributes.event_mask = (KeyPressMask | ButtonPressMask | ButtonReleaseMask | ExposureMask);
attributes.border_pixel = tmp_win->title.back;
attributes.background_pixel = tmp_win->title.back;
if (Scr->BackingStore)
{
attributes.backing_store = WhenMapped;
valuemask |= CWBackingStore;
}
tmp_win->title_w.win = XCreateWindow(dpy, tmp_win->frame,
tmp_win->frame_bw3D - tmp_win->frame_bw,
tmp_win->frame_bw3D - tmp_win->frame_bw,
(unsigned int)tmp_win->attr.width,
(unsigned int)Scr->TitleHeight,
(unsigned int)tmp_win->frame_bw,
Scr->d_depth, (unsigned int)CopyFromParent, Scr->d_visual, valuemask, &attributes);
#ifdef TWM_USE_XFT
if (Scr->use_xft > 0)
tmp_win->title_w.xft = MyXftDrawCreate(tmp_win->title_w.win);
#endif
}
else
{
tmp_win->title_w.win = 0;
tmp_win->squeeze_info = NULL;
}
if (tmp_win->highlight)
{
if (Scr->TitleBevelWidth > 0 && (Scr->Monochrome != COLOR))
tmp_win->gray = XCreatePixmapFromBitmapData(dpy, Scr->Root,
(char *)black_bits, gray_width, gray_height,
tmp_win->border_tile.fore, tmp_win->border_tile.back, Scr->d_depth);
else
tmp_win->gray = XCreatePixmapFromBitmapData(dpy, Scr->Root,
gray_bits, gray_width, gray_height,
tmp_win->border_tile.fore, tmp_win->border_tile.back, Scr->d_depth);
SetBorder(tmp_win, False);
}
else
tmp_win->gray = None;
if (tmp_win->title_w.win)
{
CreateWindowTitlebarButtons(tmp_win);
ComputeTitleLocation(tmp_win);
XMoveWindow(dpy, tmp_win->title_w.win, tmp_win->title_x, tmp_win->title_y);
XDefineCursor(dpy, tmp_win->title_w.win, Scr->TitleCursor);
}
else
{
tmp_win->title_x = tmp_win->frame_bw3D - tmp_win->frame_bw;
tmp_win->title_y = tmp_win->frame_bw3D - tmp_win->frame_bw;
}
valuemask = (CWEventMask | CWDontPropagate);
attributes.event_mask = (StructureNotifyMask | PropertyChangeMask | FocusChangeMask |
ColormapChangeMask | VisibilityChangeMask | EnterWindowMask | LeaveWindowMask);
attributes.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
XChangeWindowAttributes(dpy, tmp_win->w, valuemask, &attributes);
if (HasShape)
XShapeSelectInput(dpy, tmp_win->w, ShapeNotifyMask);
if (tmp_win->title_w.win)
{
XMapWindow(dpy, tmp_win->title_w.win);
}
if (HasShape)
{
int xws, yws, xbs, ybs;
unsigned wws, hws, wbs, hbs;
int boundingShaped, clipShaped;
XShapeSelectInput(dpy, tmp_win->w, ShapeNotifyMask);
XShapeQueryExtents(dpy, tmp_win->w, &boundingShaped, &xws, &yws, &wws, &hws, &clipShaped, &xbs, &ybs, &wbs, &hbs);
tmp_win->wShaped = boundingShaped;
}
if (HandlingEvents == TRUE /* icon managers and virtual desktop windows are created on startup */
|| (tmp_win->iconmgr == FALSE && strcmp(tmp_win->class.res_class, VTWM_DESKTOP_CLASS) != 0))
if (strcmp(tmp_win->class.res_class, VTWM_DOOR_CLASS) != 0)
XAddToSaveSet(dpy, tmp_win->w);
XReparentWindow(dpy, tmp_win->w, tmp_win->frame, tmp_win->frame_bw3D, tmp_win->title_height + tmp_win->frame_bw3D);
/*
* Reparenting generates an UnmapNotify event, followed by a MapNotify.
* Set the map state to FALSE to prevent a transition back to
* WithdrawnState in HandleUnmapNotify. Map state gets set correctly
* again in HandleMapNotify.
*/
tmp_win->mapped = FALSE;
/*
* NOW do the move and resize - windows needed to be created
* first to accomodate the opaque resources - djhjr - 4/14/98
*/
AddMoveAndResize(tmp_win, ask_user);
SetupFrame(tmp_win, tmp_win->frame_x, tmp_win->frame_y, tmp_win->frame_width, tmp_win->frame_height, -1, True);
/* wait until the window is iconified and the icon window is mapped
* before creating the icon window
*/
tmp_win->icon_w.win = None;
if (!tmp_win->iconmgr)
{
GrabButtons(tmp_win);
GrabKeys(tmp_win);
}
(void)AddIconManager(tmp_win);
XSaveContext(dpy, tmp_win->w, TwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->w, ScreenContext, (caddr_t) Scr);
XSaveContext(dpy, tmp_win->frame, TwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->frame, ScreenContext, (caddr_t) Scr);
if (tmp_win->title_height)
{
int i;
int nb = Scr->TBInfo.nleft + Scr->TBInfo.nright;
XSaveContext(dpy, tmp_win->title_w.win, TwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->title_w.win, ScreenContext, (caddr_t) Scr);
for (i = 0; i < nb; i++)
{
XSaveContext(dpy, tmp_win->titlebuttons[i].window, TwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->titlebuttons[i].window, ScreenContext, (caddr_t) Scr);
}
if (tmp_win->hilite_w)
{
XSaveContext(dpy, tmp_win->hilite_w, TwmContext, (caddr_t) tmp_win);
XSaveContext(dpy, tmp_win->hilite_w, ScreenContext, (caddr_t) Scr);
}
}
XUngrabServer(dpy);
/* if we were in the middle of a menu activated function, regrab
* the pointer
*/
if (RootFunction != F_NOFUNCTION)
ReGrab();
Scr->Newest = tmp_win;
return (tmp_win);
}
/*
* AddPaintRealWindows()
*
* a little helper for AddMoveAndResize() - djhjr - 4/15/98
*/
static void
AddPaintRealWindows(TwmWindow * tmp_win, int x, int y)
{
/* don't need to send a configure notify event */
SetupWindow(tmp_win, tmp_win->frame_x, tmp_win->frame_y, tmp_win->frame_width, tmp_win->frame_height, -1);
XMoveWindow(dpy, tmp_win->frame, x, y);
XMapWindow(dpy, tmp_win->frame);
XMapSubwindows(dpy, tmp_win->frame);
XMapSubwindows(dpy, tmp_win->title_w.win);
PaintBorderAndTitlebar(tmp_win);
if (!Scr->NoGrabServer)
{
/* these allow the application window to be drawn */
XUngrabServer(dpy);
XSync(dpy, False);
XGrabServer(dpy);
}
}
/**
* Look for a nonoccupied rectangular area to place a new client.
* If found return this area in 'pos', otherwise don't change 'pos'.
* Begin with decomposing screen empty space into (overlapping) 'tiles'.
*
* lst TWM window list
* twm new client
* tiles tile list to search
* pos return found tile
*/
#define OVERLAP(a,f) ((a)->x < (f)->frame_x+(f)->frame_width && (f)->frame_x < (a)->x+(a)->width \
&& (a)->y < (f)->frame_y+(f)->frame_height && (f)->frame_y < (a)->y+(a)->height)
static int
find_empty_area(TwmWindow * lst, TwmWindow * twm, PlaceXY * tiles, PlaceXY * pos)
{
PlaceXY *t, **pt;
/* skip unmapped windows, iconmanagers, doors and vtwm-desktop: */
while (lst != NULL && (lst->mapped == FALSE || lst->iconmgr == TRUE
|| strcmp(lst->class.res_class, VTWM_DESKTOP_CLASS) == 0 || strcmp(lst->class.res_class, VTWM_DOOR_CLASS) == 0))
lst = lst->next;
if (lst == NULL)
{
/* decomposition done, pick and return one 'tile': */
PlaceXY *m;
int w, h, d;
w = twm->attr.width + 2 * (twm->frame_bw + twm->frame_bw3D);
h = twm->attr.height + 2 * (twm->frame_bw + twm->frame_bw3D) + twm->title_height;
d = 2 * Scr->TitleHeight;
m = t = NULL;
while (tiles != NULL)
{
if (tiles->width >= w && tiles->height >= h)
{
int x, y;
x = tiles->x + twm->attr.width / 4;
y = tiles->y + twm->attr.height / 4;
if (tiles->width >= w + d && tiles->height >= h + d)
{
if ((m == NULL) || (m->y >= y) || (m->x > x))
m = tiles; /* best choice */
}
if ((t == NULL) || (t->y >= y) || (t->x > x))
t = tiles; /* second choice */
}
tiles = tiles->next;
}
if (m != NULL)
t = m;
if (t != NULL)
{
pos->x = t->x;
pos->y = t->y;
pos->width = t->width;
pos->height = t->height;
return TRUE;
}
}
else
{
/* proceed with screen 'tile' decomposition: */
for (pt = &tiles; (*pt) != NULL; pt = &((*pt)->next))
if (OVERLAP((*pt), lst))
{
PlaceXY _buf[4], *buf = _buf;
t = (*pt)->next; /*remove current tile from list */
if (lst->frame_x + lst->frame_width < (*pt)->x + (*pt)->width)
{
/* add right subtile: */
buf[0].x = lst->frame_x + lst->frame_width;
buf[0].y = (*pt)->y;
buf[0].width = (*pt)->x + (*pt)->width - (lst->frame_x + lst->frame_width);
buf[0].height = (*pt)->height;
if (buf[0].width >= twm->attr.width)
{ /*preselection */
buf[0].next = t;
t = &buf[0];
}