/
Screen.c
4818 lines (3862 loc) · 135 KB
/
Screen.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 (c) 2001, 2011 NoMachine (http://www.nomachine.com) */
/* Copyright (c) 2008-2014 Oleksandr Shneyder <o.shneyder@phoca-gmbh.de> */
/* Copyright (c) 2011-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/
/* Copyright (c) 2014-2016 Mihai Moldovan <ionic@ionic.de> */
/* Copyright (c) 2014-2016 Ulrich Sibiller <uli42@gmx.de> */
/* Copyright (c) 2015-2016 Qindel Group (http://www.qindel.com) */
/* */
/* NXAGENT, NX protocol compression and NX extensions to this software */
/* are copyright of the aforementioned persons and companies. */
/* */
/* Redistribution and use of the present software is allowed according */
/* to terms specified in the file LICENSE which comes in the source */
/* distribution. */
/* */
/* All rights reserved. */
/* */
/* NOTE: This software has received contributions from various other */
/* contributors, only the core maintainers and supporters are listed as */
/* copyright holders. Please contact us, if you feel you should be listed */
/* as copyright holder, as well. */
/* */
/**************************************************************************/
/*
Copyright 1993 by Davor Matic
Permission to use, copy, modify, distribute, and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation. Davor Matic makes no representations about
the suitability of this software for any purpose. It is provided "as
is" without express or implied warranty.
*/
/*
* Used by the auto-disconnect feature.
*/
#include <signal.h>
#include "scrnintstr.h"
#include "dix.h"
#include "dixstruct.h"
#include "mi.h"
#include "micmap.h"
#include "colormapst.h"
#include "resource.h"
#include "mipointer.h"
#include "../../fb/fb.h"
#include "../../randr/randrstr.h"
#include "inputstr.h"
#include "mivalidate.h"
#include "Agent.h"
#include "Display.h"
#include "Screen.h"
#include "Extensions.h"
#include "Atoms.h"
#include "GCs.h"
#include "GCOps.h"
#include "Image.h"
#include "Drawable.h"
#include "Font.h"
#include "Colormap.h"
#include "Cursor.h"
#include "Visual.h"
#include "Events.h"
#include "Init.h"
#include "Args.h"
#include "Client.h"
#include "Options.h"
#include "Splash.h"
#include "Holder.h"
#include "Render.h"
#include "Trap.h"
#include "Keyboard.h"
#include "Pointer.h"
#include "Reconnect.h"
#include "Composite.h"
#include <nx/Shadow.h>
#include "Utils.h"
#include <nx-X11/Xlib.h>
#include "X11/include/Xinerama_nxagent.h"
#define GC XlibGC
#define Font XlibFont
#define KeySym XlibKeySym
#define XID XlibXID
#include <nx-X11/Xlibint.h>
#undef GC
#undef Font
#undef KeySym
#undef XID
#include "Xatom.h"
#include "Xproto.h"
#include "compext/Compext.h"
#include "mibstorest.h"
/*
* Set here the required log level.
*/
#undef PANIC
#undef WARNING
#undef TEST
#undef DEBUG
#undef WATCH
#undef DUMP
/*
* Display a pixmap on an shadow
* display used for debug.
*/
#ifdef DUMP
void nxagentShowPixmap(PixmapPtr pPixmap, int x, int y, int width, int height);
void nxagentFbRestoreArea(PixmapPtr pPixmap, WindowPtr pWin, int xSrc, int ySrc, int width,
int height, int xDst, int yDst)
#endif
#ifdef WATCH
#include "unistd.h"
#endif
extern Bool nxagentIpaq;
extern Pixmap nxagentIconPixmap;
extern Pixmap nxagentIconShape;
extern Bool useXpmIcon;
extern Bool nxagentReportWindowIds;
Window nxagentDefaultWindows[MAXSCREENS];
Window nxagentInputWindows[MAXSCREENS];
Window nxagentScreenSaverWindows[MAXSCREENS];
#ifdef NXAGENT_ONSTART
Atom nxagentWMStart;
Window nxagentSplashWindow = None;
Pixmap nxagentPixmapLogo;
#endif
ScreenPtr nxagentDefaultScreen = NULL;
int nxagentArgc = 0;
char **nxagentArgv = NULL;
#ifdef NXAGENT_ARTSD
char mcop_atom[] = "MCOPGLOBALS";
Atom mcop_local_atom = None;
unsigned char fromHexNibble(char c);
void nxagentPropagateArtsdProperties(ScreenPtr pScreen, char *port);
#endif
Window nxagentIconWindow = None;
Window nxagentFullscreenWindow = None;
#ifdef VIEWPORT_FRAME
WindowPtr nxagentViewportFrameLeft;
WindowPtr nxagentViewportFrameRight;
WindowPtr nxagentViewportFrameAbove;
WindowPtr nxagentViewportFrameBelow;
#endif /* #ifdef VIEWPORT_FRAME */
Bool nxagentCreateScreenResources(ScreenPtr pScreen);
void nxagentPrintAgentGeometry(char *hdrMessage, char *prefix);
/*
* These variables are for shadowing feature.
*/
int nxagentShadowResize = 0;
WindowPtr nxagentShadowWindowPtr = NULL;
static XID accessPixmapID;
static Window accessWindowID;
static int imageByteOrder;
static unsigned char nxagentMasterDepth;
static unsigned char nxagentCheckDepth = 0;
static unsigned int nxagentBppShadow;
static unsigned int nxagentBppMaster;
int nxagentShadowXConnectionNumber;
GCPtr nxagentShadowGCPtr = NULL;
PixmapPtr nxagentShadowPixmapPtr = NULL;
char * nxagentShadowBuffer;
unsigned char nxagentShadowDepth;
int nxagentShadowWidth;
int nxagentShadowHeight;
Display * nxagentShadowDisplay;
short nxagentShadowUid = -1;
void nxagentShadowAdaptDepth(unsigned int, unsigned int, unsigned int, char **);
RegionRec nxagentShadowUpdateRegion;
#define NXAGENT_DEFAULT_DPI 75
/*
* From randr/randr.c. This was originally static
* but we need it here.
*/
int TellChanged(WindowPtr pWin, void * value);
int nxagentBitsPerPixel(int depth)
{
if (depth == 1) return 1;
else if (depth <= 8) return 8;
else if (depth <= 16) return 16;
else return 32;
}
void nxagentSetScreenInfo(ScreenInfo *screenInfo)
{
/*
* Setup global screen info parameters. In the Xnest
* server this stuff is done after having opened the
* real display as Xnest lets the screen reflect the
* order of the remote end. Agent will instead set
* the order according to local endianess and swap
* data whenever it is appropriate.
*
* From a standard implementation:
*
* screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
* screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
* screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
* screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
*
* From Xnest implementation:
*
* screenInfo -> imageByteOrder = ImageByteOrder(nxagentDisplay);
* screenInfo -> bitmapScanlineUnit = BitmapUnit(nxagentDisplay);
* screenInfo -> bitmapScanlinePad = BitmapPad(nxagentDisplay);
* screenInfo -> bitmapBitOrder = BitmapBitOrder(nxagentDisplay);
*/
screenInfo -> imageByteOrder = IMAGE_BYTE_ORDER;
screenInfo -> bitmapScanlinePad = BITMAP_SCANLINE_PAD;
screenInfo -> bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
screenInfo -> bitmapBitOrder = BITMAP_BIT_ORDER;
#ifdef TEST
fprintf(stderr, "nxagentSetScreenInfo: Server image order is [%d] bitmap order is [%d].\n",
screenInfo -> imageByteOrder, screenInfo -> bitmapBitOrder);
fprintf(stderr, "nxagentSetScreenInfo: Server scanline unit is [%d] scanline pad is [%d].\n",
screenInfo -> bitmapScanlineUnit, screenInfo -> bitmapScanlinePad);
#endif
}
void nxagentSetPixmapFormats(ScreenInfo *screenInfo)
{
int i;
/*
* Formats are created with no care of which are supported
* on the real display. Creating only formats supported
* by the remote end makes troublesome handling migration
* of session from a display to another.
*/
screenInfo -> numPixmapFormats = nxagentNumPixmapFormats;
for (i = 0; i < nxagentNumPixmapFormats; i++)
{
screenInfo -> formats[i].depth = nxagentPixmapFormats[i].depth;
screenInfo -> formats[i].bitsPerPixel = nxagentPixmapFormats[i].bits_per_pixel;
screenInfo -> formats[i].scanlinePad = nxagentPixmapFormats[i].scanline_pad;
#ifdef TEST
fprintf(stderr, "nxagentSetPixmapFormats: Set format at index [%d] to depth [%d] "
"bits per pixel [%d] scanline pad [%d].\n", i,
screenInfo -> formats[i].depth, screenInfo -> formats[i].bitsPerPixel,
screenInfo -> formats[i].scanlinePad);
#endif
}
}
void nxagentMinimizeFromFullScreen(ScreenPtr pScreen)
{
XUnmapWindow(nxagentDisplay, nxagentFullscreenWindow);
if (nxagentIpaq)
{
XMapWindow(nxagentDisplay, nxagentIconWindow);
XIconifyWindow(nxagentDisplay, nxagentIconWindow,
DefaultScreen(nxagentDisplay));
}
else
{
XIconifyWindow(nxagentDisplay, nxagentIconWindow,
DefaultScreen(nxagentDisplay));
}
}
void nxagentMaximizeToFullScreen(ScreenPtr pScreen)
{
if (nxagentIpaq)
{
XUnmapWindow(nxagentDisplay, nxagentIconWindow);
XMapWindow(nxagentDisplay, nxagentFullscreenWindow);
}
else
{
/*
XUnmapWindow(nxagentDisplay, nxagentIconWindow);
*/
/*
FIXME: We'll check for ReparentNotify and LeaveNotify events after XReparentWindow()
in order to avoid the session window is iconified.
We could avoid the sesssion window is iconified when a LeaveNotify event is received,
so this check would be unnecessary.
*/
struct timeval timeout;
int i;
XEvent e;
XReparentWindow(nxagentDisplay, nxagentFullscreenWindow,
RootWindow(nxagentDisplay, DefaultScreen(nxagentDisplay)), 0, 0);
for (i = 0; i < 100 && nxagentWMIsRunning; i++)
{
#ifdef TEST
fprintf(stderr, "nxagentMaximizeToFullscreen: WARNING! Going to wait for the ReparentNotify event.\n");
#endif
if (XCheckTypedWindowEvent(nxagentDisplay, nxagentFullscreenWindow, ReparentNotify, &e))
{
break;
}
XSync(nxagentDisplay, 0);
timeout.tv_sec = 0;
timeout.tv_usec = 50 * 1000;
nxagentWaitEvents(nxagentDisplay, &timeout);
}
XMapRaised(nxagentDisplay, nxagentFullscreenWindow);
XIconifyWindow(nxagentDisplay, nxagentIconWindow,
DefaultScreen(nxagentDisplay));
while (XCheckTypedWindowEvent(nxagentDisplay, nxagentFullscreenWindow, LeaveNotify, &e));
/*
XMapWindow(nxagentDisplay, nxagentIconWindow);
*/
}
}
Window nxagentCreateIconWindow()
{
XSetWindowAttributes attributes;
unsigned long valuemask;
char* window_name;
XTextProperty windowName;
XSizeHints sizeHints;
XWMHints wmHints;
Window w;
Mask mask;
/*
* Create icon window.
*/
attributes.override_redirect = False;
attributes.colormap = DefaultColormap(nxagentDisplay, DefaultScreen(nxagentDisplay));
attributes.background_pixmap = nxagentScreenSaverPixmap;
valuemask = CWOverrideRedirect | CWBackPixmap | CWColormap;
#ifdef TEST
fprintf(stderr, "nxagentCreateIconWindow: Going to create new icon window.\n");
#endif
w = XCreateWindow(nxagentDisplay, DefaultRootWindow(nxagentDisplay),
0, 0, 1, 1, 0,
DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)),
InputOutput,
DefaultVisual(nxagentDisplay, DefaultScreen(nxagentDisplay)),
valuemask, &attributes);
if (nxagentReportWindowIds)
{
fprintf (stderr, "NXAGENT_WINDOW_ID: ICON_WINDOW,WID:[0x%x]\n", nxagentIconWindow);
}
#ifdef TEST
fprintf(stderr, "nxagentCreateIconWindow: Created new icon window with id [0x%x].\n",
nxagentIconWindow);
#endif
/*
* Set hints to the window manager for the icon window.
*/
window_name = nxagentWindowName;
XStringListToTextProperty(&window_name, 1, &windowName);
sizeHints.flags = PMinSize | PMaxSize;
sizeHints.min_width = sizeHints.max_width = 1;
sizeHints.min_height = sizeHints.max_height = 1;
wmHints.flags = IconPixmapHint | IconMaskHint;
wmHints.initial_state = IconicState;
wmHints.icon_pixmap = nxagentIconPixmap;
if (useXpmIcon)
{
wmHints.icon_mask = nxagentIconShape;
wmHints.flags = IconPixmapHint | IconMaskHint;
}
else
{
wmHints.flags = StateHint | IconPixmapHint;
}
XSetWMProperties(nxagentDisplay, w,
&windowName, &windowName,
NULL , 0 , &sizeHints, &wmHints, NULL);
/*
* Enable events from the icon window.
*/
nxagentGetDefaultEventMask(&mask);
XSelectInput(nxagentDisplay, w, (mask & ~(KeyPressMask |
KeyReleaseMask)) | StructureNotifyMask);
/*
* Notify to client if user closes icon window.
*/
if (nxagentWMIsRunning && !nxagentOption(Rootless))
{
XlibAtom deleteWMAtom = nxagentAtoms[2]; /* WM_DELETE_WINDOW */
XSetWMProtocols(nxagentDisplay, w, &deleteWMAtom, 1);
}
return w;
}
Bool nxagentMagicPixelZone(int x, int y)
{
return (x >= nxagentOption(Width) - 1 && y < 1);
}
void nxagentSetScreenSaverTime(void)
{
#ifdef TEST
fprintf(stderr, "nxagentSetScreenSaverTime: ScreenSaverTime was [%lu], ScreenSaverInterval was [%lu].\n",
(long unsigned int)ScreenSaverTime, (long unsigned int)ScreenSaverInterval);
#endif
/*
* More than one timeout could be used here,
* to make use of screen-saver handler not
* only for the timeout feature. In a case
* like this, the lower timeout have to be
* used as ScreenSaverTime.
*/
if (nxagentAutoDisconnectTimeout > 0)
{
ScreenSaverTime = nxagentAutoDisconnectTimeout;
}
ScreenSaverInterval = ScreenSaverTime;
#ifdef TEST
fprintf(stderr, "nxagentSetScreenSaverTime: ScreenSaverTime now is [%lu], ScreenSaverInterval now is [%lu].\n",
(long unsigned int)ScreenSaverTime, (long unsigned int)ScreenSaverInterval);
#endif
}
static Bool nxagentSaveScreen(ScreenPtr pScreen, int what)
{
#ifdef TEST
fprintf(stderr, "nxagentSaveScreen: Called for screen at [%p] with parameter [%d].\n",
(void *) pScreen, what);
fprintf(stderr, "nxagentSaveScreen: SCREEN_SAVER_ON is [%d] SCREEN_SAVER_OFF is [%d] "
"SCREEN_SAVER_FORCER is [%d] SCREEN_SAVER_CYCLE is [%d].\n",
SCREEN_SAVER_ON, SCREEN_SAVER_OFF, SCREEN_SAVER_FORCER,
SCREEN_SAVER_CYCLE);
#endif
/*
* We need only to reset the timeouts
* in this case.
*/
if (what == SCREEN_SAVER_OFF)
{
nxagentAutoDisconnectTimeout = nxagentOption(Timeout) * MILLI_PER_SECOND;
return 1;
}
/*
* The lastDeviceEventTime is updated every time
* a device event is received, and it is used by
* WaitForSomething() to know when the SaveScreens()
* function should be called. This solution doesn't
* take care of a pointer button not released, so
* we have to handle this case by ourselves.
*/
/*
FIXME: Do we need to check the key grab if the
autorepeat feature is disabled?
*/
if (inputInfo.pointer -> button -> buttonsDown > 0)
{
#ifdef TEST
fprintf(stderr, "nxagentSaveScreen: Ignoring timeout, there is a pointer button down.\n");
#endif
/*
* Returning 0 the SaveScreens() function
* (which calls this one) tries to build
* a screen-saver creating a new window.
* We don't want this, so we return 1 in
* any case.
*/
return 1;
}
/*
* Handling the auto-disconnect feature.
* If there is any client attached and the persisten-
* ce is allowed then leave the session running, else
* terminate it. It should use something less brutal,
* though raising a signal should ensure that the code
* follows the usual execution path.
*/
if (nxagentOption(Timeout) > 0)
{
#ifdef TEST
fprintf(stderr, "nxagentSaveScreen: Auto-disconnect timeout was [%d].\n",
nxagentAutoDisconnectTimeout);
#endif
nxagentAutoDisconnectTimeout -= ScreenSaverTime;
#ifdef TEST
fprintf(stderr, "nxagentSaveScreen: Auto-disconnect timeout is [%d].\n",
nxagentAutoDisconnectTimeout);
#endif
if (nxagentSessionState == SESSION_UP &&
nxagentAutoDisconnectTimeout <= 0)
{
nxagentAutoDisconnectTimeout = nxagentOption(Timeout) * MILLI_PER_SECOND;
if (nxagentClients == 0)
{
fprintf(stderr, "Info: Terminating session with no client running.\n");
raise(SIGTERM);
}
else if (nxagentOption(Persistent) == 0)
{
fprintf(stderr, "Info: Terminating session with persistence not allowed.\n");
raise(SIGTERM);
}
else
{
fprintf(stderr, "Info: Suspending session with %d clients running.\n",
nxagentClients);
raise(SIGHUP);
}
}
}
return 1;
}
Bool nxagentCreateScreenResources(ScreenPtr pScreen)
{
Bool ret;
CreatePixmapProcPtr savedCreatePixmap = pScreen->CreatePixmap;
ModifyPixmapHeaderProcPtr savedModifyPixmapHeader = pScreen->ModifyPixmapHeader;
pScreen->CreatePixmap = fbCreatePixmap;
pScreen->ModifyPixmapHeader = miModifyPixmapHeader;
ret = miCreateScreenResources(pScreen);
pScreen->CreatePixmap = savedCreatePixmap;
pScreen->ModifyPixmapHeader = savedModifyPixmapHeader;
return ret;
}
static Bool nxagentCursorOffScreen(ScreenPtr *pPtrScreen, int *x, int *y)
{
return False;
}
static void nxagentCrossScreen(ScreenPtr pScreen, Bool entering)
{
}
static miPointerScreenFuncRec nxagentPointerCursorFuncs =
{
nxagentCursorOffScreen,
nxagentCrossScreen,
miPointerWarpCursor
};
#ifdef VIEWPORT_FRAME
void nxagentInitViewportFrame(ScreenPtr pScreen, WindowPtr pRootWin)
{
int error = Success;
VisualID visual = 0;
int i;
XID xid;
if (nxagentOption(Rootless))
{
return;
}
for (i = 0; i < pScreen -> numDepths; i++)
{
if (pScreen -> allowedDepths[i].depth == pRootWin -> drawable.depth)
{
visual = pScreen -> allowedDepths[i].vids[0];
break;
}
}
/*
* It is not necessary create the windows on the real X server. But this
* windows are not visible. Create them it is not a great effort, and avoids
* many errors.
*
* nxagentScreenTrap = True;
*/
xid = FakeClientID(serverClient -> index);
#ifdef TEST
fprintf(stderr, "nxagentInitViewportFrame: XID = [%lx]\n", xid);
#endif
nxagentViewportFrameLeft = CreateWindow(xid, pRootWin, -NXAGENT_FRAME_WIDTH, 0, NXAGENT_FRAME_WIDTH,
pRootWin -> drawable.height,
0, InputOutput, 0, NULL,
pRootWin -> drawable.depth,
serverClient, visual, &error);
AddResource(xid, RT_WINDOW, (void *) nxagentViewportFrameLeft);
if (error != Success)
{
#ifdef WARNING
fprintf(stderr, "nxagentInitViewportFrame: Error creating nxagentViewportFrameLeft.\n");
#endif
error = Success;
}
xid = FakeClientID(serverClient -> index);
#ifdef TEST
fprintf(stderr, "nxagentInitViewportFrame: XID = [%lx]\n", xid);
#endif
nxagentViewportFrameRight = CreateWindow(xid, pRootWin, pRootWin -> drawable.width, 0,
NXAGENT_FRAME_WIDTH,
pRootWin -> drawable.height,
0, InputOutput, 0, NULL,
pRootWin -> drawable.depth,
serverClient, visual,
&error);
AddResource(xid, RT_WINDOW, (void *) nxagentViewportFrameRight);
if (error != Success)
{
#ifdef WARNING
fprintf(stderr, "nxagentInitViewportFrame: Error creating nxagentViewportFrameRight.\n");
#endif
error = Success;
}
xid = FakeClientID(serverClient -> index);
#ifdef TEST
fprintf(stderr, "nxagentInitViewportFrame: XID = [%lx]\n", xid);
#endif
nxagentViewportFrameAbove = CreateWindow(xid, pRootWin, 0, -NXAGENT_FRAME_WIDTH,
pRootWin -> drawable.width,
NXAGENT_FRAME_WIDTH, 0,
InputOutput, 0, NULL,
pRootWin -> drawable.depth,
serverClient, visual,
&error);
AddResource(xid, RT_WINDOW, (void *) nxagentViewportFrameAbove);
if (error != Success)
{
#ifdef WARNING
fprintf(stderr, "nxagentInitViewportFrame: Error creating nxagentViewportFrameAbove.\n");
#endif
error = Success;
}
xid = FakeClientID(serverClient -> index);
#ifdef TEST
fprintf(stderr, "nxagentInitViewportFrame: XID = [%lx]\n", xid);
#endif
nxagentViewportFrameBelow = CreateWindow(xid, pRootWin, 0,
pRootWin -> drawable.height,
pRootWin -> drawable.width,
NXAGENT_FRAME_WIDTH, 0,
InputOutput, 0, NULL,
pRootWin -> drawable.depth,
serverClient, visual, &error);
AddResource(xid, RT_WINDOW, (void *) nxagentViewportFrameBelow);
if (error != Success)
{
#ifdef WARNING
fprintf(stderr, "nxagentInitViewportFrame: Error creating nxagentViewportFrameBelow.\n");
#endif
}
nxagentViewportFrameLeft -> overrideRedirect = 1;
nxagentViewportFrameRight -> overrideRedirect = 1;
nxagentViewportFrameAbove -> overrideRedirect = 1;
nxagentViewportFrameBelow -> overrideRedirect = 1;
MapWindow(nxagentViewportFrameLeft, serverClient);
MapWindow(nxagentViewportFrameRight, serverClient);
MapWindow(nxagentViewportFrameAbove, serverClient);
MapWindow(nxagentViewportFrameBelow, serverClient);
/*
* nxagentScreenTrap = False;
*/
}
#endif /* #ifdef VIEWPORT_FRAME */
void nxagentPrintAgentGeometry(char *hdrMessage, char *prefix)
{
#ifdef WARNING
if (prefix == NULL)
{
prefix = "";
}
if (hdrMessage)
{
fprintf(stderr, "--------------- %s -----------------.\n", hdrMessage);
}
fprintf(stderr, "%s Root window at offset (%d,%d) size (%d,%d).\n", prefix,
nxagentOption(RootX), nxagentOption(RootY),
nxagentOption(RootWidth), nxagentOption(RootHeight));
fprintf(stderr, "%s Default window at offset (%d,%d) size (%d,%d) border size %d.\n", prefix,
nxagentOption(X), nxagentOption(Y), nxagentOption(Width), nxagentOption(Height),
nxagentOption(BorderWidth));
fprintf(stderr, "%s Span between root window and default window is (%d,%d).\n", prefix,
nxagentOption(ViewportXSpan), nxagentOption(ViewportYSpan));
fprintf(stderr, "%s Default window in window mode has offset (%d,%d) and size (%d,%d).\n", prefix,
nxagentOption(SavedX), nxagentOption(SavedY), nxagentOption(SavedWidth), nxagentOption(SavedHeight));
fprintf(stderr, "%s Fullscreen is %s.\n", prefix,
nxagentOption(Fullscreen) ? "ON" : "OFF");
fprintf(stderr, "%s Desktop resize mode is %s.\n", prefix,
nxagentOption(DesktopResize) ? "ON" : "OFF");
fprintf(stderr, "%s Resize desktop at startup is %s.\n", prefix,
nxagentResizeDesktopAtStartup ? "ON" : "OFF");
#endif
}
static int nxagentColorOffset(unsigned long mask)
{
int count;
for (count = 0; !(mask & 1) && count < 32; count++)
{
mask >>= 1;
}
return count;
}
Bool nxagentOpenScreen(ScreenPtr pScreen,
int argc, char *argv[])
{
VisualPtr visuals;
DepthPtr depths;
int numVisuals, numDepths;
int i, j, depthIndex;
unsigned long valuemask;
XSetWindowAttributes attributes;
XWindowAttributes gattributes;
XSizeHints sizeHints;
XWMHints wmHints;
Mask mask;
Bool resetAgentPosition = False;
VisualID defaultVisual;
int rootDepth;
void * pFrameBufferBits;
int bitsPerPixel;
int sizeInBytes;
int defaultVisualIndex = 0;
#ifdef TEST
fprintf(stderr, "nxagentOpenScreen: Called for screen index [%d].\n",
pScreen->myNum);
#endif
if (nxagentRenderEnable && nxagentReconnectTrap == False)
{
PictureScreenPrivateIndex = -1;
}
nxagentDefaultScreen = pScreen;
nxagentQueryAtoms(pScreen);
#ifdef NXAGENT_ONSTART
nxagentWMStart = nxagentAtoms[3]; /* WM_NX_READY */
#endif
/*
* Forced geometry parameter
* to user geometry.
*/
if (nxagentResizeDesktopAtStartup)
{
if (nxagentUserGeometry.flag & XValue)
{
nxagentChangeOption(X, nxagentUserGeometry.X);
}
if (nxagentUserGeometry.flag & YValue)
{
nxagentChangeOption(Y, nxagentUserGeometry.Y);
}
if (nxagentUserGeometry.flag & WidthValue)
{
nxagentChangeOption(Width, nxagentUserGeometry.Width);
nxagentChangeOption(RootWidth, nxagentUserGeometry.Width);
if (nxagentOption(SavedWidth) > nxagentUserGeometry.Width)
{
nxagentChangeOption(SavedWidth, nxagentUserGeometry.Width);
}
}
if (nxagentUserGeometry.flag & HeightValue)
{
nxagentChangeOption(Height, nxagentUserGeometry.Height);
nxagentChangeOption(RootHeight, nxagentUserGeometry.Height);
if (nxagentOption(SavedHeight) > nxagentUserGeometry.Height)
{
nxagentChangeOption(SavedHeight, nxagentUserGeometry.Height);
}
}
}
/*
* This is first time the
* screen is initialized.
* Filling the geometry parameter
* from user geometry.
*/
if (nxagentReconnectTrap == False)
{
if (nxagentUserGeometry.flag & XValue)
{
nxagentChangeOption(X, nxagentUserGeometry.X);
}
if (nxagentUserGeometry.flag & YValue)
{
nxagentChangeOption(Y, nxagentUserGeometry.Y);
}
if (nxagentUserGeometry.flag & WidthValue)
{
nxagentChangeOption(RootWidth, nxagentUserGeometry.Width);
}
if (nxagentUserGeometry.flag & HeightValue)
{
nxagentChangeOption(RootHeight, nxagentUserGeometry.Height);
}
}
else if (nxagentWMIsRunning && !nxagentOption(Rootless) && !nxagentOption(Fullscreen))
{
/*
* At reconnection, try to estimate the shift due to WM reparenting.
*/
if (nxagentOption(X) >= 6)
{
nxagentChangeOption(X, nxagentOption(X) - 6);
}
if (nxagentOption(Y) >= 25)
{
nxagentChangeOption(Y, nxagentOption(Y) - 25);
}
}
/*
* Determine the size of the root window.
* It is the maximum size of the screen
* if we are either in rootless or in
* fullscreen mode.
*/
if (nxagentOption(Rootless) == False && nxagentWMIsRunning == False)
{
#ifdef TEST
fprintf(stderr, "nxagentOpenScreen: Forcing fullscreen mode with no window manager running.\n");
#endif
nxagentChangeOption(Fullscreen, True);
if (nxagentOption(ClientOs) == ClientOsWinnt &&
(nxagentReconnectTrap == False || nxagentResizeDesktopAtStartup))
{
NXSetExposeParameters(nxagentDisplay, 0, 0, 0);
}
}
if (nxagentOption(Fullscreen) &&
nxagentWMIsRunning &&
nxagentReconnectTrap &&
nxagentResizeDesktopAtStartup == False &&
nxagentXServerGeometryChanged())
{
#ifdef TEST
fprintf(stderr, "nxagentOpenScreen: Forcing window mode with server geometry changed.\n");
#endif
nxagentChangeOption(Fullscreen, False);
nxagentChangeOption(AllScreens, False);
nxagentFullscreenWindow = 0;
resetAgentPosition = True;
}
if (nxagentOption(Fullscreen))
{
nxagentChangeOption(X, 0);