-
Notifications
You must be signed in to change notification settings - Fork 0
/
twm.c
1749 lines (1465 loc) · 47.3 KB
/
twm.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: twm.c,v 1.124 91/05/08 11:01:54 dave Exp $
*
* vtwm - Virtually "Tom's Window Manager"
*
* 27-Oct-87 Thomas E. LaStrange File created
* 10-Oct-90 David M. Sternlicht Storing saved colors on root
***********************************************************************/
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include "twm.h"
#include "add_window.h"
#include "gc.h"
#include "parse.h"
#include "version.h"
#include "menus.h"
#include "events.h"
#include "image_formats.h"
#include "util.h"
#include "gram.h"
#include "screen.h"
#include "iconmgr.h"
#include "desktop.h"
#ifdef SOUND_SUPPORT
#include "sound.h"
#ifdef HAVE_OSS
#include <sys/wait.h>
#endif
#endif
#include "prototypes.h"
#include <X11/Xresource.h>
#include <X11/Xproto.h>
#include <X11/Xatom.h>
#include <X11/Xmu/Error.h>
#include <X11/Xlocale.h>
#ifdef TWM_USE_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#include <X11/Xos.h>
Display *dpy; /* which display are we talking to */
Window ResizeWindow; /* the window we are resizing */
int MultiScreen = TRUE; /* try for more than one screen? */
int NumScreens; /* number of screens in ScreenList */
int NumButtons; /* number of mouse buttons */
volatile int IsDone = 0; /* Have we received an out-of-band request for termination? */
volatile int ReqWakeup = 0; /* Are we in a position to need a wakeup from X? */
int HasShape; /* server supports shape extension? */
int ShapeEventBase, ShapeErrorBase;
#ifdef TWM_USE_XRANDR
int HasXrandr; /* server supports XRANDR extension? */
int XrandrEventBase, XrandrErrorBase;
#endif
ScreenInfo **ScreenList; /* structures for each screen */
ScreenInfo *Scr = NULL; /* the cur and prev screens */
int PreviousScreen; /* last screen that we were on */
int FirstScreen; /* TRUE ==> first screen of display */
Bool PrintPID = False; /* controls PID file - djhjr - 12/2/01 */
int PrintErrorMessages = 0; /* controls error messages */
static int RedirectError; /* TRUE ==> another window manager running */
static int CatchRedirectError(Display * dpy, XErrorEvent * event); /* for settting RedirectError */
static int TwmErrorHandler(Display * dpy, XErrorEvent * event); /* for everything else */
static void InitVariables(void);
static void InternUsefulAtoms(void);
char Info[INFO_LINES][INFO_SIZE]; /* info strings to print */
int InfoLines;
char *InitFile = NULL;
int parseInitFile = TRUE;
Cursor UpperLeftCursor; /* upper Left corner cursor */
Cursor RightButt;
Cursor MiddleButt;
Cursor LeftButt;
XContext TwmContext; /* context for twm windows */
XContext MenuContext; /* context for all menu windows */
XContext IconManagerContext; /* context for all window list windows */
XContext VirtualContext; /* context for all desktop display windows */
XContext ScreenContext; /* context to get screen data */
XContext ColormapContext; /* context for colormap operations */
XContext DoorContext; /* context for doors */
XClassHint NoClass; /* for applications with no class */
XGCValues Gcv;
char *Home; /* the HOME environment variable */
int HomeLen; /* length of Home */
int ParseError; /* error parsing the .twmrc file */
int HandlingEvents = FALSE; /* are we handling events yet? */
Window JunkRoot; /* junk window */
Window JunkChild; /* junk window */
int JunkX; /* junk variable */
int JunkY; /* junk variable */
unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth, JunkMask;
char *ProgramName, *PidName = "vtwm.pid";
int Argc;
char **Argv;
char **Environ;
Bool RestartPreviousState = False; /* try to restart in previous state */
Bool AutoResizeKeepOnScreen = False; /* True means a non-user initiated resize should keep window fully on-screen if previously fully on-screen */
unsigned long black, white;
Bool use_fontset;
TwmWindow *Focus; /* the twm window that has focus */
short FocusRoot; /* is the input focus on the root ? */
#ifdef TWM_USE_SLOPPYFOCUS
int SloppyFocus; /* TRUE if sloppy focus policy globally on all screens activated */
#endif
int RecoverStolenFocusAttempts; /* Number of attempts vtwm should try to return focus if some client stole it */
int RecoverStolenFocusTimeout; /* Time in milliseconds vtwm should fight for returning focus if some client stole it */
/***********************************************************************
*
* Procedure:
* main - start of twm
*
***********************************************************************
*/
/* Changes for m4 pre-processing submitted by Jason Gloudon */
int
main(int argc, char **argv, char **environ)
{
Window root, parent, *children;
unsigned int nchildren;
int i, j;
char *def, *display_name = NULL;
unsigned long valuemask; /* mask for create windows */
XSetWindowAttributes attributes; /* attributes for create windows */
int numManaged, firstscrn, lastscrn, scrnum;
int use_C_locale = 0;
#ifndef NO_M4_SUPPORT
int m4_preprocess = False; /* filter the *twmrc file through m4 */
char *m4_option = NULL; /* pass these options to m4 - djhjr - 2/20/98 */
#endif
#ifdef SOUND_SUPPORT
int sound_state = 0;
#endif
extern char *defTwmrc[];
char *loc;
#ifdef TWM_USE_XFT
int xft_available;
#endif
#ifdef TWM_USE_XINERAMA
short xinerama_available;
#endif
#ifdef TWM_USE_SLOPPYFOCUS
SloppyFocus = FALSE;
#endif
RecoverStolenFocusAttempts = 0; /* zero value means no focus recovery attempts are made (set in .vtwmrc) */
RecoverStolenFocusTimeout = -1; /* negative value means no focus recovery attempts are made (estimated) */
if ((ProgramName = strrchr(argv[0], '/')))
ProgramName++;
else
ProgramName = argv[0];
Argc = argc;
Argv = argv;
Environ = environ;
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
switch (argv[i][1])
{
case 'c':
use_C_locale = 1;
continue;
case 'd': /* -display display */
if (++i >= argc)
goto usage;
display_name = argv[i];
continue;
case 'f': /* -file [initfile] */
/* this isn't really right, but hey... - djhjr - 10/7/02 */
if (i + 1 < argc && (argv[i + 1][0] != '-' || (argv[i + 1][0] == '-' && !strchr("dfmpsv", argv[i + 1][1]))))
InitFile = argv[++i];
else
parseInitFile = FALSE;
continue;
#ifndef NO_M4_SUPPORT
case 'm': /* -m4 [options] */
m4_preprocess = True;
/* this isn't really right, but hey... - djhjr - 2/20/98 */
if (i + 1 < argc && (argv[i + 1][0] != '-' || (argv[i + 1][0] == '-' && !strchr("dfmpsv", argv[i + 1][1]))))
m4_option = argv[++i];
continue;
#endif
case 'p': /* -pidfile - djhjr - 12/2/01 */
PrintPID = True;
continue;
case 's': /* -single */
MultiScreen = FALSE;
continue;
case 'v': /* -verbose */
++PrintErrorMessages;
continue;
case 'V':
printf("%s\n", Version);
#ifdef DOC_CFLAGS
printf("Compile flags: %s\n", DOC_CFLAGS);
#endif /*DOC_CFLAGS*/
exit(0);
}
}
usage:
fprintf(stderr,
#ifndef NO_M4_SUPPORT
"usage: %s [-c] [-d display] [-f [initfile]] [-m [options]] [-p] [-s] [-v] [-V]\n\n"
"\t-m <OPTION> -- M4 conditional configuration defintion\n"
#else
"usage: %s [-c] [-d display] [-f [initfile]] [-p] [-s] [-v] [-V]\n\n"
#endif
"\t-d <display> -- Use in place of $DISPLAY\n"
"\t-f <path> -- Init file in place of ~/.vtwmrc\n"
"\t-p -- print vtwm PID\n"
"\t-s -- only run on one screen on DISPLAY\n"
"\t-v -- print error message\n"
"\t-V -- print version\n",
ProgramName);
exit(1);
}
loc = setlocale(LC_ALL, "");
if (use_C_locale || !loc || !strcmp(loc, "C") || !strcmp(loc, "POSIX") || !XSupportsLocale())
use_fontset = False;
else
use_fontset = True;
if (PrintErrorMessages)
fprintf(stderr, "%s: L10N %sabled.\n", ProgramName, (use_fontset) ? "en" : "dis");
#ifdef SOUND_SUPPORT
#define sounddonehandler(sig) \
if (signal (sig, SIG_IGN) != SIG_IGN) (void) signal (sig, PlaySoundDone)
#else
#define sounddonehandler(sig) \
if (signal (sig, SIG_IGN) != SIG_IGN) (void) signal (sig, Done)
#endif
#define donehandler(sig) \
if (signal (sig, SIG_IGN) != SIG_IGN) (void) signal (sig, Done)
sounddonehandler(SIGINT);
sounddonehandler(SIGHUP);
sounddonehandler(SIGQUIT);
sounddonehandler(SIGTERM);
#ifdef SOUND_SUPPORT
/* cjp - 2007/01/08 Collect child processes from playing sounds */
#ifdef HAVE_OSS
signal(SIGCHLD,HandleChildExit);
#endif
#endif
#if 0
donehandler(SIGABRT);
donehandler(SIGFPE);
donehandler(SIGSEGV);
donehandler(SIGILL);
donehandler(SIGTSTP);
donehandler(SIGPIPE);
#endif
#undef sounddonehandler
#undef donehandler
#if !defined(HAS_SETPGID) && !defined(HAS_SETGRP) && !defined(HAS_SETSID)
{
sigset_t set;
sigemptyset(&set);
#ifdef SIGTTIN
sigaddset(&set, SIGTTIN);
#endif
#ifdef SIGTTOU
sigaddset(&set, SIGTTOU);
#endif
if (sigprocmask(SIG_BLOCK, &set, NULL) < 0)
perror("sigprocmask-initial-block");
}
#endif
signal(SIGUSR1, QueueRestartVtwm);
Home = getenv("HOME");
if (Home == NULL)
Home = "./";
HomeLen = strlen(Home);
NoClass.res_name = NoName;
NoClass.res_class = NoName;
if (!(dpy = XOpenDisplay(display_name)))
{
fprintf(stderr, "%s: unable to open display \"%s\"\n", ProgramName, XDisplayName(display_name));
exit(1);
}
if (fcntl(ConnectionNumber(dpy), F_SETFD, 1) == -1)
{
fprintf(stderr, "%s: unable to mark display connection as close-on-exec\n", ProgramName);
exit(1);
}
#ifdef TWM_USE_XFT
if (FcTrue == XftInit(0) && FcTrue == XftInitFtLibrary())
{
xft_available = TRUE;
if (PrintErrorMessages)
{
i = XftGetVersion();
fprintf(stderr, "%s: Xft subsystem (runtime version %d.%d.%d) initialised.\n",
ProgramName, i / 10000, (i / 100) % 100, i % 100);
}
}
else
{
xft_available = FALSE;
if (PrintErrorMessages)
{
i = XftVersion;
fprintf(stderr,
"%s: FreeType/Xft(%d.%d.%d)/Xrender not available (using X11 core fonts).\n",
ProgramName, i / 10000, (i / 100) % 100, i % 100);
}
}
#endif
#ifdef TWM_USE_XINERAMA
xinerama_available = FALSE;
if (XineramaQueryExtension(dpy, &JunkX, &JunkY) == True)
if (XineramaQueryVersion(dpy, &JunkX, &JunkY))
if (XineramaIsActive(dpy) == True)
xinerama_available = TRUE;
if (PrintErrorMessages)
{
if (xinerama_available == TRUE)
fprintf(stderr, "%s: Xinerama extension (version %d.%d) is available.\n", ProgramName, JunkX, JunkY);
else
fprintf(stderr, "%s: Xinerama extension is not available.\n", ProgramName);
}
#endif
#ifdef TWM_USE_XRANDR
HasXrandr = XRRQueryExtension(dpy, &XrandrEventBase, &XrandrErrorBase);
if (PrintErrorMessages)
{
if (HasXrandr == True)
{
if (!XRRQueryVersion(dpy, &JunkX, &JunkY))
JunkX = JunkY = -1;
fprintf(stderr, "%s: Xrandr extension (version %d.%d) is available.\n", ProgramName, JunkX, JunkY);
}
else
fprintf(stderr, "%s: Xrandr extension is not available.\n", ProgramName);
}
#endif
HasShape = XShapeQueryExtension(dpy, &ShapeEventBase, &ShapeErrorBase);
TwmContext = XUniqueContext();
MenuContext = XUniqueContext();
IconManagerContext = XUniqueContext();
VirtualContext = XUniqueContext();
ScreenContext = XUniqueContext();
ColormapContext = XUniqueContext();
DoorContext = XUniqueContext();
InternUsefulAtoms();
/* Set up the per-screen global information. */
NumScreens = ScreenCount(dpy);
{
unsigned char pmap[256]; /* there are 8 bits of buttons */
NumButtons = XGetPointerMapping(dpy, pmap, 256);
}
if (MultiScreen)
{
firstscrn = 0;
lastscrn = NumScreens - 1;
}
else
{
firstscrn = lastscrn = DefaultScreen(dpy);
}
InfoLines = 0;
/* for simplicity, always allocate NumScreens ScreenInfo struct pointers */
ScreenList = (ScreenInfo **) calloc(NumScreens, sizeof(ScreenInfo *));
if (ScreenList == NULL)
{
fprintf(stderr, "%s: Unable to allocate memory for screen list, exiting.\n", ProgramName);
exit(1);
}
numManaged = 0;
PreviousScreen = DefaultScreen(dpy);
FirstScreen = TRUE;
for (scrnum = firstscrn; scrnum <= lastscrn; scrnum++)
{
/* Make sure property priority colors is empty */
XChangeProperty(dpy, RootWindow(dpy, scrnum), _XA_MIT_PRIORITY_COLORS, XA_CARDINAL, 32, PropModeReplace, NULL, 0);
RedirectError = FALSE;
XSetErrorHandler(CatchRedirectError);
XSelectInput(dpy, RootWindow(dpy, scrnum),
ColormapChangeMask | EnterWindowMask | FocusChangeMask | PropertyChangeMask |
SubstructureRedirectMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask);
XSync(dpy, False);
XSetErrorHandler(TwmErrorHandler);
if (RedirectError)
{
fprintf(stderr, "%s: another window manager is already running", ProgramName);
if (MultiScreen && NumScreens > 0)
fprintf(stderr, " on screen %d?\n", scrnum);
else
fprintf(stderr, "?\n");
continue;
}
numManaged++;
/* Note: ScreenInfo struct is calloc'ed to initialize to zero. */
Scr = ScreenList[scrnum] = (ScreenInfo *) calloc(1, sizeof(ScreenInfo));
if (Scr == NULL)
{
fprintf(stderr, "%s: unable to allocate memory for ScreenInfo structure for screen %d.\n", ProgramName, scrnum);
continue;
}
Scr->Mouse = calloc((NumButtons + 1) * NUM_CONTEXTS * MOD_SIZE, sizeof(MouseButton));
if (!Scr->Mouse)
{
fprintf(stderr, "%s: Unable to allocate memory for mouse buttons, exiting.\n", ProgramName);
exit(1);
}
/* initialize list pointers, remember to put an initialization
* in InitVariables also
*/
Scr->BorderColorL = NULL;
Scr->IconBorderColorL = NULL;
Scr->BorderTileForegroundL = NULL;
Scr->BorderTileBackgroundL = NULL;
Scr->TitleForegroundL = NULL;
Scr->TitleBackgroundL = NULL;
Scr->IconForegroundL = NULL;
Scr->IconBackgroundL = NULL;
Scr->NoTitle = NULL;
Scr->MakeTitle = NULL;
Scr->AutoRaise = NULL;
Scr->IconNames = NULL;
Scr->NoHighlight = NULL;
Scr->NoStackModeL = NULL;
Scr->NoTitleHighlight = NULL;
Scr->DontIconify = NULL;
Scr->IconMgrNoShow = NULL;
Scr->IconMgrShow = NULL;
Scr->IconifyByUn = NULL;
Scr->IconManagerFL = NULL;
Scr->IconManagerBL = NULL;
Scr->IconMgrs = NULL;
Scr->StartIconified = NULL;
Scr->SqueezeTitleL = NULL;
Scr->DontSqueezeTitleL = NULL;
Scr->WindowRingL = NULL;
Scr->NoWindowRingL = NULL;
Scr->WarpCursorL = NULL;
Scr->ImageCache = NULL;
Scr->OpaqueMoveL = NULL;
Scr->NoOpaqueMoveL = NULL;
Scr->OpaqueResizeL = NULL;
Scr->NoOpaqueResizeL = NULL;
Scr->NoBorder = NULL;
Scr->UsePPositionL = NULL;
/* remember to put an initialization in InitVariables also
*/
Scr->screen = scrnum;
Scr->d_depth = DefaultDepth(dpy, scrnum);
Scr->d_visual = DefaultVisual(dpy, scrnum);
Scr->Root = RootWindow(dpy, scrnum);
XSaveContext(dpy, Scr->Root, ScreenContext, (caddr_t) Scr);
if ((def = XGetDefault(dpy, "*", "bitmapFilePath")))
Scr->BitmapFilePath = strdup(def);
else
Scr->BitmapFilePath = NULL;
Scr->TwmRoot.cmaps.number_cwins = 1;
Scr->TwmRoot.cmaps.cwins = (ColormapWindow **) malloc(sizeof(ColormapWindow *));
Scr->TwmRoot.cmaps.cwins[0] = CreateColormapWindow(Scr->Root, True, False);
Scr->TwmRoot.cmaps.cwins[0]->visibility = VisibilityPartiallyObscured;
Scr->cmapInfo.cmaps = NULL;
Scr->cmapInfo.maxCmaps = MaxCmapsOfScreen(ScreenOfDisplay(dpy, Scr->screen));
Scr->cmapInfo.root_pushes = 0;
InstallWindowColormaps(0, &Scr->TwmRoot);
Scr->StdCmapInfo.head = Scr->StdCmapInfo.tail = Scr->StdCmapInfo.mru = NULL;
Scr->StdCmapInfo.mruindex = 0;
LocateStandardColormaps();
Scr->TBInfo.nleft = Scr->TBInfo.nright = 0;
Scr->TBInfo.head = NULL;
Scr->TBInfo.border = -100;
Scr->TBInfo.width = 0;
Scr->TBInfo.leftx = 0;
Scr->TBInfo.titlex = 0;
#ifdef TILED_SCREEN
Scr->tile_names = NULL;
Scr->tiles = NULL;
Scr->ntiles = 0;
#endif
#ifdef TWM_USE_XRANDR
if (HasXrandr == True)
{
XEvent e;
XRRSelectInput (dpy, Scr->Root, RRScreenChangeNotifyMask);
XSync (dpy, False);
while (XCheckTypedWindowEvent(dpy, Scr->Root,
XrandrEventBase+RRScreenChangeNotify, &e) == True)
{
XRRUpdateConfiguration (&e);
}
GetXrandrTilesGeometries (Scr);
}
#endif
#ifdef TWM_USE_XINERAMA
if (xinerama_available == TRUE && Scr->tiles == NULL)
GetXineramaTilesGeometries (Scr);
#endif
Scr->MyDisplayWidth = DisplayWidth(dpy, scrnum);
Scr->MyDisplayHeight = DisplayHeight(dpy, scrnum);
Scr->MaxWindowWidth = 32767 - Scr->MyDisplayWidth;
Scr->MaxWindowHeight = 32767 - Scr->MyDisplayHeight;
#ifdef TILED_SCREEN
/* prerequisite: Scr->MyDisplayWidth, Scr->MyDisplayHeight are initialised: */
Scr->use_tiles = ComputeTiledAreaBoundingBox (Scr);
#endif
Scr->XORvalue = (((unsigned long)1) << Scr->d_depth) - 1;
if (DisplayCells(dpy, scrnum) < 3)
Scr->Monochrome = MONOCHROME;
else
Scr->Monochrome = COLOR;
/* set up default colors */
Scr->FirstTime = TRUE;
GetColor(Scr->Monochrome, &black, "black");
Scr->Black = black;
GetColor(Scr->Monochrome, &white, "white");
Scr->White = white;
if (FirstScreen)
{
FocusRoot = TRUE;
Focus = NULL;
SetFocus((TwmWindow *) NULL, CurrentTime);
/* define cursors */
NewFontCursor(&UpperLeftCursor, "top_left_corner");
NewFontCursor(&RightButt, "rightbutton");
NewFontCursor(&LeftButt, "leftbutton");
NewFontCursor(&MiddleButt, "middlebutton");
}
Scr->iconmgr.geometry = "";
Scr->iconmgr.x = 0;
Scr->iconmgr.y = 0;
Scr->iconmgr.width = 150;
Scr->iconmgr.height = 5;
Scr->iconmgr.next = NULL;
Scr->iconmgr.prev = NULL;
Scr->iconmgr.lasti = &(Scr->iconmgr);
Scr->iconmgr.first = NULL;
Scr->iconmgr.last = NULL;
Scr->iconmgr.active = NULL;
Scr->iconmgr.scr = Scr;
Scr->iconmgr.columns = 1;
Scr->iconmgr.count = 0;
Scr->iconmgr.name = "VTWM";
Scr->iconmgr.icon_name = "Icons";
Scr->IconDirectory = NULL;
Scr->hiliteName = NULL;
Scr->menuIconName = TBPM_MENU;
Scr->iconMgrIconName = TBPM_XLOGO;
Scr->hiliteName = NULL;
Scr->hilitePm = NULL;
Scr->virtualPm = NULL;
Scr->realscreenPm = NULL;
if (Scr->FirstTime)
{ /* retain max size on restart. */
Scr->VirtualDesktopMaxWidth = 0;
Scr->VirtualDesktopMaxHeight = 0;
}
#ifdef TWM_USE_XFT
if (xft_available == TRUE)
Scr->use_xft = 0; /* evtl. .vtwmrc sets this to '+1' */
else
Scr->use_xft = -1; /* remains '-1' */
#endif
InitVariables();
InitMenus();
if (!parseInitFile)
ParseStringList(defTwmrc);
else
{
/* Parse it once for each screen. */
#ifndef NO_M4_SUPPORT
ParseTwmrc(InitFile, display_name, m4_preprocess, m4_option);
#else
ParseTwmrc(InitFile);
#endif
}
#ifdef SOUND_SUPPORT
OpenSound();
if (PlaySound(S_START))
{
/*
* Save setting from resource file, and turn sound off
*/
sound_state = ToggleSounds();
sound_state ^= 1;
if (sound_state == 0)
ToggleSounds();
}
#endif
assign_var_savecolor(); /* storeing pixels for twmrc "entities" */
if (Scr->FramePadding == -100)
Scr->FramePadding = 2; /* values that look */
if (Scr->TitlePadding == -100)
Scr->TitlePadding = 8; /* "nice" on */
if (Scr->ButtonIndent == -100)
Scr->ButtonIndent = 1; /* 75 and 100dpi displays */
if (Scr->TBInfo.border == -100)
Scr->TBInfo.border = 1;
if (!Scr->BeNiceToColormap)
GetShadeColors(&Scr->TitleC);
if (!Scr->BeNiceToColormap)
GetShadeColors(&Scr->MenuC);
if (Scr->MenuBevelWidth > 0 && !Scr->BeNiceToColormap)
GetShadeColors(&Scr->MenuTitleC);
if (Scr->BorderBevelWidth > 0 && !Scr->BeNiceToColormap)
GetShadeColors(&Scr->BorderColorC);
if (Scr->DoorBevelWidth > 0 && !Scr->BeNiceToColormap)
GetShadeColors(&Scr->DoorC);
if (Scr->VirtualDesktopBevelWidth > 0 && !Scr->BeNiceToColormap)
GetShadeColors(&Scr->VirtualC);
{
if (2 * Scr->BorderBevelWidth > Scr->BorderWidth)
Scr->BorderWidth = 2 * Scr->BorderBevelWidth;
if (!Scr->BeNiceToColormap)
GetShadeColors(&Scr->DefaultC);
}
if (Scr->IconBevelWidth > 0)
Scr->IconBorderWidth = 0;
if (Scr->SqueezeTitle == -1)
Scr->SqueezeTitle = FALSE;
if (!Scr->HaveFonts)
CreateFonts();
CreateGCs();
MakeMenus();
/* set titlebar height to font height plus frame padding */
Scr->TitleHeight = Scr->TitleBarFont.height + Scr->FramePadding * 2;
if (!(Scr->TitleHeight & 1))
Scr->TitleHeight++;
i = InitTitlebarButtons(); /* returns the button height */
/* adjust titlebar height to button height */
if (i > Scr->TitleHeight)
Scr->TitleHeight = i + Scr->FramePadding * 2;
if (!(Scr->TitleHeight & 1))
Scr->TitleHeight++;
/* adjust font baseline */
Scr->TitleBarFont.y += ((Scr->TitleHeight - Scr->TitleBarFont.height) / 2);
XGrabServer(dpy);
XSync(dpy, False);
JunkX = 0;
JunkY = 0;
XQueryTree(dpy, Scr->Root, &root, &parent, &children, &nchildren);
CreateIconManagers();
if (Scr->Virtual == TRUE)
{
CreateDesktopDisplay();
DoInitialMapping(Scr->VirtualDesktopDisplayTwin);
}
/* create all of the door windows */
door_open_all();
/*
* weed out icon windows
*/
for (i = 0; i < nchildren; i++)
{
if (children[i])
{
XWMHints *wmhintsp = XGetWMHints(dpy, children[i]);
if (wmhintsp)
{
if (wmhintsp->flags & IconWindowHint)
{
for (j = 0; j < nchildren; j++)
{
if (children[j] == wmhintsp->icon_window)
{
children[j] = None;
break;
}
}
}
XFree((char *)wmhintsp);
}
}
}
/*
* map all of the non-override windows
*/
for (i = 0; i < nchildren; i++)
{
if (children[i] && MappedNotOverride(children[i]))
{
XUnmapWindow(dpy, children[i]);
SimulateMapRequest(children[i]);
}
}
if (!Scr->NoIconManagers)
{
IconMgr *ip;
for (ip = &Scr->iconmgr; ip != NULL; ip = ip->next)
if (Scr->ShowIconManager) {
if (ip->count > 0)
DoInitialMapping(ip->twm_win);
} else
ip->twm_win->icon = TRUE;
}
if (!(Scr->InfoBevelWidth > 0))
attributes.border_pixel = Scr->DefaultC.fore;
attributes.background_pixel = Scr->DefaultC.back;
attributes.event_mask = (ExposureMask | ButtonPressMask | KeyPressMask | ButtonReleaseMask);
attributes.backing_store = NotUseful;
if (!(Scr->InfoBevelWidth > 0))
valuemask = (CWBorderPixel | CWBackPixel | CWEventMask | CWBackingStore);
else
valuemask = (CWBackPixel | CWEventMask | CWBackingStore);
Scr->InfoWindow.win = XCreateWindow(dpy, Scr->Root, 0, 0,
(unsigned int)5, (unsigned int)5,
(unsigned int)(Scr->InfoBevelWidth > 0 ? 0 : Scr->BorderWidth), 0,
(unsigned int)CopyFromParent, (Visual *) CopyFromParent, valuemask, &attributes);
Scr->SizeStringWidth = MyFont_TextWidth(&Scr->SizeFont,
"nnnnnnnnnnnnn", 13) + ((Scr->InfoBevelWidth > 0) ? 2 * Scr->InfoBevelWidth : 0);
if (!Scr->InfoBevelWidth > 0)
valuemask = (CWBorderPixel | CWBackPixel | CWBitGravity);
else
valuemask = (CWBackPixel | CWBitGravity);
switch (Scr->ResizeX)
{
case R_NORTHWEST:
Scr->ResizeX = 20;
Scr->ResizeY = 20;
break;
case R_NORTHEAST:
Scr->ResizeX = (Scr->MyDisplayWidth - Scr->SizeStringWidth) - 20;
Scr->ResizeY = 20;
break;
case R_SOUTHWEST:
Scr->ResizeX = 20;
Scr->ResizeY = (Scr->MyDisplayHeight - (Scr->SizeFont.height + SIZE_VINDENT * 2)) - 20;
break;
case R_SOUTHEAST:
Scr->ResizeX = (Scr->MyDisplayWidth - Scr->SizeStringWidth) - 20;
Scr->ResizeY = (Scr->MyDisplayHeight - (Scr->SizeFont.height + SIZE_VINDENT * 2)) - 20;
break;
case R_CENTERED:
Scr->ResizeX = (Scr->MyDisplayWidth - Scr->SizeStringWidth) / 2;
Scr->ResizeY = (Scr->MyDisplayHeight - (Scr->SizeFont.height + SIZE_VINDENT * 2)) / 2;
break;
}
attributes.bit_gravity = NorthWestGravity;
Scr->SizeWindow.win = XCreateWindow(dpy, Scr->Root,
Scr->ResizeX, Scr->ResizeY,
(unsigned int)Scr->SizeStringWidth,
(unsigned int)(Scr->SizeFont.height + SIZE_VINDENT * 2) +
((Scr->InfoBevelWidth > 0) ? 2 * Scr->InfoBevelWidth : 0),
(unsigned int)(Scr->InfoBevelWidth > 0 ? 0 : Scr->BorderWidth), 0,
(unsigned int)CopyFromParent, (Visual *) CopyFromParent, valuemask, &attributes);
#ifdef TWM_USE_XFT
if (Scr->use_xft > 0)
{
Scr->InfoWindow.xft = MyXftDrawCreate(Scr->InfoWindow.win);
Scr->SizeWindow.xft = MyXftDrawCreate(Scr->SizeWindow.win);
CopyPixelToXftColor(Scr->DefaultC.fore, &Scr->DefaultC.xft);
}
#endif
#if defined TWM_USE_OPACITY
SetWindowOpacity(Scr->InfoWindow.win, Scr->MenuOpacity);
#endif
XUngrabServer(dpy);
FirstScreen = FALSE;
Scr->FirstTime = FALSE;
} /* for */
if (numManaged == 0)
{
if (MultiScreen && NumScreens > 0)
fprintf(stderr, "%s: unable to find any unmanaged screens\n", ProgramName);
exit(1);
}
/* measure X11-server roundtrip and estimate 'RecoverStolenFocusTimeout': */
if (RecoverStolenFocusAttempts == 0) /* '0' means no recovery attempts */
RecoverStolenFocusTimeout = -1;
else if (RecoverStolenFocusAttempts == 1)
RecoverStolenFocusTimeout = 0; /* timeout '0' means try once */
if (RecoverStolenFocusAttempts > 1)
{
struct timeval start, stop;
long long roundtrip;
XImage *image;
XSync(dpy, False);
X_GETTIMEOFDAY(&start);
image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 1, 1, ~0, ZPixmap);
if (image) XDestroyImage(image);
XSync(dpy, False);
image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), 0, DisplayHeight(dpy, DefaultScreen(dpy))-1, 1, 1, ~0, ZPixmap);
if (image) XDestroyImage(image);
XSync(dpy, False);
image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), DisplayWidth(dpy, DefaultScreen(dpy))-1, 0, 1, 1, ~0, ZPixmap);
if (image) XDestroyImage(image);
XSync(dpy, False);
image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), DisplayWidth(dpy, DefaultScreen(dpy))-1, DisplayHeight(dpy, DefaultScreen(dpy))-1, 1, 1, ~0, ZPixmap);
if (image) XDestroyImage(image);
XSync(dpy, False);
X_GETTIMEOFDAY(&stop);
if (stop.tv_usec < start.tv_usec)
{
stop.tv_usec += 1000000;
stop.tv_sec -= 1;
}
roundtrip = (long long)(stop.tv_usec - start.tv_usec) + (long long)(stop.tv_sec - start.tv_sec) * 1000000;
/* set focus recovery timeout (milliseconds) proportional to X11-server roundtrip (microseconds): */
RecoverStolenFocusTimeout = 20; /* fast */
if (roundtrip > (long long)(500))
RecoverStolenFocusTimeout = 100; /* slower */
if (roundtrip > (long long)(2000))
RecoverStolenFocusTimeout = 500; /* slower */
if (roundtrip > (long long)(5000))
RecoverStolenFocusTimeout = 900; /* slowest */
if (PrintErrorMessages)
fprintf(stderr, "%s: X11-server roundtrip calibration %ld microseconds, focus recovery timeout := %d milliseconds (or %d attempts).\n",
ProgramName, (long)roundtrip, RecoverStolenFocusTimeout, RecoverStolenFocusAttempts);
}
RestartPreviousState = False;
HandlingEvents = TRUE;
RaiseStickyAbove();
RaiseAutoPan(); /* autopan windows should have been raised
* after [re]starting vtwm -- DSE */
InitEvents();
/* profile function stuff by DSE */
#define VTWM_PROFILE "VTWM Profile"
if (FindMenuRoot(VTWM_PROFILE))
{
ExecuteFunction(F_FUNCTION, VTWM_PROFILE, 0, 0, 0, Event.xany.window, &Scr->TwmRoot, &Event, C_NO_CONTEXT, FALSE);
}
#ifdef SOUND_SUPPORT
/* restore setting from resource file */
if (sound_state == 1)
ToggleSounds();
#endif
/* write out a PID file - djhjr - 12/2/01 */
if (PrintPID)
{
int fd, err = 0;
char buf[10], *fn = malloc(HomeLen + strlen(PidName) + 2);
if (! fn) {
perror("malloc");
exit(1);