forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GX11Gui.cxx
2903 lines (2397 loc) · 92.8 KB
/
GX11Gui.cxx
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
// @(#)root/x11:$Id$
// Author: Fons Rademakers 28/12/97
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
/** \class TGX11
*/
// This file contains the implementation of the GUI methods of the
// TGX11 class. Most of the methods are used by the machine independent
// GUI classes (libGUI.so).
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <X11/xpm.h>
#include "TGX11.h"
#include "TROOT.h"
#include "TError.h"
#include "TSystem.h"
#include "TException.h"
#include "TClassTable.h"
#include "KeySymbols.h"
#include "TEnv.h"
#include <X11/extensions/shape.h>
//---- MWM Hints stuff
struct MWMHintsProperty_t {
Handle_t fFlags;
Handle_t fFunctions;
Handle_t fDecorations;
Int_t fInputMode;
};
//---- hints
const ULong_t kMWMHintsFunctions = BIT(0);
const ULong_t kMWMHintsDecorations = BIT(1);
const ULong_t kMWMHintsInputMode = BIT(2);
const Int_t kPropMotifWMHintsElements = 4;
const Int_t kPropMWMHintElements = kPropMotifWMHintsElements;
//---- Key symbol mapping
struct KeySymbolMap_t {
KeySym fXKeySym;
EKeySym fKeySym;
};
//---- Mapping table of all non-trivial mappings (the ASCII keys map
//---- one to one so are not included)
static KeySymbolMap_t gKeyMap[] = {
{ XK_Escape, kKey_Escape },
{ XK_Tab, kKey_Tab },
#ifndef XK_ISO_Left_Tab
{ 0xFE20, kKey_Backtab },
#else
{ XK_ISO_Left_Tab, kKey_Backtab },
#endif
{ XK_BackSpace, kKey_Backspace },
{ XK_Return, kKey_Return },
{ XK_Insert, kKey_Insert },
{ XK_Delete, kKey_Delete },
{ XK_Clear, kKey_Delete },
{ XK_Pause, kKey_Pause },
{ XK_Print, kKey_Print },
{ 0x1005FF60, kKey_SysReq }, // hardcoded Sun SysReq
{ 0x1007ff00, kKey_SysReq }, // hardcoded X386 SysReq
{ XK_Home, kKey_Home }, // cursor movement
{ XK_End, kKey_End },
{ XK_Left, kKey_Left },
{ XK_Up, kKey_Up },
{ XK_Right, kKey_Right },
{ XK_Down, kKey_Down },
{ XK_Prior, kKey_Prior },
{ XK_Next, kKey_Next },
{ XK_Shift_L, kKey_Shift }, // modifiers
{ XK_Shift_R, kKey_Shift },
{ XK_Shift_Lock, kKey_Shift },
{ XK_Control_L, kKey_Control },
{ XK_Control_R, kKey_Control },
{ XK_Meta_L, kKey_Meta },
{ XK_Meta_R, kKey_Meta },
{ XK_Alt_L, kKey_Alt },
{ XK_Alt_R, kKey_Alt },
{ XK_Caps_Lock, kKey_CapsLock },
{ XK_Num_Lock, kKey_NumLock },
{ XK_Scroll_Lock, kKey_ScrollLock },
{ XK_KP_Space, kKey_Space }, // numeric keypad
{ XK_KP_Tab, kKey_Tab },
{ XK_KP_Enter, kKey_Enter },
{ XK_KP_F1, kKey_F1 },
{ XK_KP_F2, kKey_F2 },
{ XK_KP_F3, kKey_F3 },
{ XK_KP_F4, kKey_F4 },
{ XK_KP_Home, kKey_Home },
{ XK_KP_Left, kKey_Left },
{ XK_KP_Up, kKey_Up },
{ XK_KP_Right, kKey_Right },
{ XK_KP_Down, kKey_Down },
{ XK_KP_Prior, kKey_Prior },
{ XK_KP_Page_Up, kKey_PageUp },
{ XK_KP_Next, kKey_Next },
{ XK_KP_Page_Down, kKey_PageDown },
{ XK_KP_End, kKey_End },
{ XK_KP_Begin, kKey_Home },
{ XK_KP_Insert, kKey_Insert },
{ XK_KP_Delete, kKey_Delete },
{ XK_KP_Equal, kKey_Equal },
{ XK_KP_Multiply, kKey_Asterisk },
{ XK_KP_Add, kKey_Plus },
{ XK_KP_Separator, kKey_Comma },
{ XK_KP_Subtract, kKey_Minus },
{ XK_KP_Decimal, kKey_Period },
{ XK_KP_Divide, kKey_Slash },
{ 0, (EKeySym) 0 }
};
struct RXGCValues:XGCValues{};
struct RXColor:XColor{};
struct RXpmAttributes:XpmAttributes{};
struct RXSetWindowAttributes:XSetWindowAttributes{};
struct RVisual:Visual{};
////////////////////////////////////////////////////////////////////////////////
inline void SplitLong(Long_t ll, Long_t &i1, Long_t &i2)
{
union { Long_t l; Int_t i[2]; } conv;
conv.l = ll;
i1 = conv.i[0];
i2 = conv.i[1];
}
////////////////////////////////////////////////////////////////////////////////
inline void AsmLong(Long_t i1, Long_t i2, Long_t &ll)
{
union { Long_t l; Int_t i[2]; } conv;
conv.i[0] = (Int_t) i1;
conv.i[1] = (Int_t) i2;
ll = conv.l;
}
////////////////////////////////////////////////////////////////////////////////
/// Handle X11 error.
static Int_t RootX11ErrorHandler(Display *disp, XErrorEvent *err)
{
char msg[80];
XGetErrorText(disp, err->error_code, msg, 80);
// force segV. to allow backtracing the error with gdb
if (gDebug == (Long_t)gVirtualX) {
gSystem->ProcessEvents();
::Error("RootX11ErrorHandler", "%s (XID: %u, XREQ: %u)", msg,
(UInt_t)err->resourceid, err->request_code);
int *kil = (int*)1;
delete kil;
return 0;
}
if (!err->resourceid) return 0;
TObject *w = (TObject *)gROOT->ProcessLineFast(Form("gClient->GetWindowById(%lu)", (ULong_t)err->resourceid));
if (!w) {
::Error("RootX11ErrorHandler", "%s (XID: %u, XREQ: %u)", msg,
(UInt_t)err->resourceid, err->request_code);
} else {
::Error("RootX11ErrorHandler", "%s (%s XID: %u, XREQ: %u)", msg, w->ClassName(),
(UInt_t)err->resourceid, err->request_code);
w->Print("tree");
}
if (TROOT::Initialized()) {
//Getlinem(kInit, "Root > ");
Throw(2);
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Handle X11 I/O error (happens when connection to display server
/// is broken).
static Int_t RootX11IOErrorHandler(Display *)
{
::Error("RootX11IOErrorHandler", "fatal X11 error (connection to server lost?!)");
fprintf(stderr,"\n**** Save data and exit application ****\n\n");
// delete X connection handler (to avoid looping in TSystem::DispatchOneEvent())
if (gXDisplay && gSystem) {
gSystem->RemoveFileHandler(gXDisplay);
SafeDelete(gXDisplay);
}
if (TROOT::Initialized()) {
//Getlinem(kInit, "Root > ");
Throw(2);
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Map window on screen.
void TGX11::MapWindow(Window_t id)
{
if (!id) return;
XMapWindow((Display*)fDisplay, (Window) id);
}
////////////////////////////////////////////////////////////////////////////////
/// Map sub windows.
void TGX11::MapSubwindows(Window_t id)
{
if (!id) return;
XMapSubwindows((Display*)fDisplay, (Window) id);
}
////////////////////////////////////////////////////////////////////////////////
/// Map window on screen and put on top of all windows.
void TGX11::MapRaised(Window_t id)
{
if (!id) return;
XMapRaised((Display*)fDisplay, (Window) id);
}
////////////////////////////////////////////////////////////////////////////////
/// Unmap window from screen.
void TGX11::UnmapWindow(Window_t id)
{
if (!id) return;
XUnmapWindow((Display*)fDisplay, (Window) id);
}
////////////////////////////////////////////////////////////////////////////////
/// Destroy window.
void TGX11::DestroyWindow(Window_t id)
{
if (!id) return;
XDestroyWindow((Display*)fDisplay, (Window) id);
}
////////////////////////////////////////////////////////////////////////////////
/// Destroy subwindows of this window.
void TGX11::DestroySubwindows(Window_t id)
{
if (!id) return;
XDestroySubwindows((Display*)fDisplay, (Window) id);
}
////////////////////////////////////////////////////////////////////////////////
/// Put window on top of window stack.
void TGX11::RaiseWindow(Window_t id)
{
if (!id) return;
XRaiseWindow((Display*)fDisplay, (Window) id);
}
////////////////////////////////////////////////////////////////////////////////
/// Lower window so it lays below all its siblings.
void TGX11::LowerWindow(Window_t id)
{
if (!id) return;
XLowerWindow((Display*)fDisplay, (Window) id);
}
////////////////////////////////////////////////////////////////////////////////
/// Move a window.
void TGX11::MoveWindow(Window_t id, Int_t x, Int_t y)
{
if (!id) return;
XMoveWindow((Display*)fDisplay, (Window) id, x, y);
}
////////////////////////////////////////////////////////////////////////////////
/// Move and resize a window.
void TGX11::MoveResizeWindow(Window_t id, Int_t x, Int_t y, UInt_t w, UInt_t h)
{
if (!id) return;
XMoveResizeWindow((Display*)fDisplay, (Window) id, x, y, w, h);
}
////////////////////////////////////////////////////////////////////////////////
/// Resize the window.
void TGX11::ResizeWindow(Window_t id, UInt_t w, UInt_t h)
{
if (!id) return;
// protect against potential negative values
if (w >= (UInt_t)INT_MAX || h >= (UInt_t)INT_MAX)
return;
XResizeWindow((Display*)fDisplay, (Window) id, w, h);
}
////////////////////////////////////////////////////////////////////////////////
/// Iconify the window.
void TGX11::IconifyWindow(Window_t id)
{
if (!id) return;
XIconifyWindow((Display*)fDisplay, (Window) id, fScreenNumber);
}
////////////////////////////////////////////////////////////////////////////////
/// Reparent window to new parent window at position (x,y).
void TGX11::ReparentWindow(Window_t id, Window_t pid, Int_t x, Int_t y)
{
if (!id) return;
XReparentWindow((Display*)fDisplay, (Window) id, (Window) pid, x, y);
}
////////////////////////////////////////////////////////////////////////////////
/// Set the window background color.
void TGX11::SetWindowBackground(Window_t id, ULong_t color)
{
if (!id) return;
XSetWindowBackground((Display*)fDisplay, (Window) id, color);
}
////////////////////////////////////////////////////////////////////////////////
/// Set pixmap as window background.
void TGX11::SetWindowBackgroundPixmap(Window_t id, Pixmap_t pxm)
{
if (!id) return;
XSetWindowBackgroundPixmap((Display*)fDisplay, (Window) id, (Pixmap) pxm);
}
////////////////////////////////////////////////////////////////////////////////
/// Return handle to newly created X window.
Window_t TGX11::CreateWindow(Window_t parent, Int_t x, Int_t y,
UInt_t w, UInt_t h, UInt_t border,
Int_t depth, UInt_t clss,
void *visual, SetWindowAttributes_t *attr, UInt_t)
{
RXSetWindowAttributes xattr;
ULong_t xmask = 0;
if (attr)
MapSetWindowAttributes(attr, xmask, xattr);
if (depth == 0)
depth = fDepth;
if (visual == 0)
visual = fVisual;
if (fColormap && !(xmask & CWColormap)) {
xmask |= CWColormap;
xattr.colormap = fColormap;
}
if ((Window)parent == fRootWin && fRootWin != fVisRootWin) {
xmask |= CWBorderPixel;
xattr.border_pixel = fBlackPixel;
}
return (Window_t) XCreateWindow((Display*)fDisplay, (Window) parent, x, y,
w, h, border, depth, clss, (Visual*)visual,
xmask, &xattr);
}
////////////////////////////////////////////////////////////////////////////////
/// Map event mask to or from X.
void TGX11::MapEventMask(UInt_t &emask, UInt_t &xemask, Bool_t tox)
{
if (tox) {
Long_t lxemask = NoEventMask;
if ((emask & kKeyPressMask))
lxemask |= KeyPressMask;
if ((emask & kKeyReleaseMask))
lxemask |= KeyReleaseMask;
if ((emask & kButtonPressMask))
lxemask |= ButtonPressMask;
if ((emask & kButtonReleaseMask))
lxemask |= ButtonReleaseMask;
if ((emask & kPointerMotionMask))
lxemask |= PointerMotionMask;
if ((emask & kButtonMotionMask))
lxemask |= ButtonMotionMask;
if ((emask & kExposureMask))
lxemask |= ExposureMask;
if ((emask & kStructureNotifyMask))
lxemask |= StructureNotifyMask;
if ((emask & kEnterWindowMask))
lxemask |= EnterWindowMask;
if ((emask & kLeaveWindowMask))
lxemask |= LeaveWindowMask;
if ((emask & kFocusChangeMask))
lxemask |= FocusChangeMask;
if ((emask & kOwnerGrabButtonMask))
lxemask |= OwnerGrabButtonMask;
if ((emask & kColormapChangeMask))
lxemask |= ColormapChangeMask;
xemask = (UInt_t)lxemask;
} else {
emask = 0;
if ((xemask & KeyPressMask))
emask |= kKeyPressMask;
if ((xemask & KeyReleaseMask))
emask |= kKeyReleaseMask;
if ((xemask & ButtonPressMask))
emask |= kButtonPressMask;
if ((xemask & ButtonReleaseMask))
emask |= kButtonReleaseMask;
if ((xemask & PointerMotionMask))
emask |= kPointerMotionMask;
if ((xemask & ButtonMotionMask))
emask |= kButtonMotionMask;
if ((xemask & ExposureMask))
emask |= kExposureMask;
if ((xemask & StructureNotifyMask))
emask |= kStructureNotifyMask;
if ((xemask & EnterWindowMask))
emask |= kEnterWindowMask;
if ((xemask & LeaveWindowMask))
emask |= kLeaveWindowMask;
if ((xemask & FocusChangeMask))
emask |= kFocusChangeMask;
if ((xemask & OwnerGrabButtonMask))
emask |= kOwnerGrabButtonMask;
if ((xemask & ColormapChangeMask))
emask |= kColormapChangeMask;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Map a SetWindowAttributes_t to a XSetWindowAttributes structure.
void TGX11::MapSetWindowAttributes(SetWindowAttributes_t *attr,
ULong_t &xmask, RXSetWindowAttributes &xattr)
{
Mask_t mask = attr->fMask;
xmask = 0;
if ((mask & kWABackPixmap)) {
xmask |= CWBackPixmap;
if (attr->fBackgroundPixmap == kNone)
xattr.background_pixmap = None;
else if (attr->fBackgroundPixmap == kParentRelative)
xattr.background_pixmap = ParentRelative;
else
xattr.background_pixmap = (Pixmap)attr->fBackgroundPixmap;
}
if ((mask & kWABackPixel)) {
xmask |= CWBackPixel;
xattr.background_pixel = attr->fBackgroundPixel;
}
if ((mask & kWABorderPixmap)) {
xmask |= CWBorderPixmap;
xattr.border_pixmap = (Pixmap)attr->fBorderPixmap;
}
if ((mask & kWABorderPixel)) {
xmask |= CWBorderPixel;
xattr.border_pixel = attr->fBorderPixel;
}
if ((mask & kWABitGravity)) {
xmask |= CWBitGravity;
xattr.bit_gravity = attr->fBitGravity; //assume ident mapping (rdm)
}
if ((mask & kWAWinGravity)) {
xmask |= CWWinGravity;
xattr.win_gravity = attr->fWinGravity; // assume ident mapping (rdm)
}
if ((mask & kWABackingStore)) {
xmask |= CWBackingStore;
if (attr->fBackingStore == kNotUseful)
xattr.backing_store = NotUseful;
else if (attr->fBackingStore == kWhenMapped)
xattr.backing_store = WhenMapped;
else if (attr->fBackingStore == kAlways)
xattr.backing_store = Always;
else
xattr.backing_store = attr->fBackingStore;
}
if ((mask & kWABackingPlanes)) {
xmask |= CWBackingPlanes;
xattr.backing_planes = attr->fBackingPlanes;
}
if ((mask & kWABackingPixel)) {
xmask |= CWBackingPixel;
xattr.backing_pixel = attr->fBackingPixel;
}
if ((mask & kWAOverrideRedirect)) {
xmask |= CWOverrideRedirect;
xattr.override_redirect = attr->fOverrideRedirect;
}
if ((mask & kWASaveUnder)) {
xmask |= CWSaveUnder;
xattr.save_under = (Bool)attr->fSaveUnder;
}
if ((mask & kWAEventMask)) {
xmask |= CWEventMask;
UInt_t xmsk, msk = (UInt_t) attr->fEventMask;
MapEventMask(msk, xmsk, kTRUE);
xattr.event_mask = xmsk;
}
if ((mask & kWADontPropagate)) {
xmask |= CWDontPropagate;
xattr.do_not_propagate_mask = attr->fDoNotPropagateMask;
}
if ((mask & kWAColormap)) {
xmask |= CWColormap;
xattr.colormap = (Colormap)attr->fColormap;
}
if ((mask & kWACursor)) {
xmask |= CWCursor;
if (attr->fCursor == kNone)
xattr.cursor = None;
else
xattr.cursor = (Cursor)attr->fCursor;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Map a GCValues_t to a XCGValues structure if tox is true. Map
/// the other way in case tox is false.
void TGX11::MapGCValues(GCValues_t &gval,
ULong_t &xmask, RXGCValues &xgval, Bool_t tox)
{
if (tox) {
// map GCValues_t to XGCValues
Mask_t mask = gval.fMask;
xmask = 0;
if ((mask & kGCFunction)) {
xmask |= GCFunction;
xgval.function = gval.fFunction; // ident mapping
}
if ((mask & kGCPlaneMask)) {
xmask |= GCPlaneMask;
xgval.plane_mask = gval.fPlaneMask;
}
if ((mask & kGCForeground)) {
xmask |= GCForeground;
xgval.foreground = gval.fForeground;
}
if ((mask & kGCBackground)) {
xmask |= GCBackground;
xgval.background = gval.fBackground;
}
if ((mask & kGCLineWidth)) {
xmask |= GCLineWidth;
xgval.line_width = gval.fLineWidth;
}
if ((mask & kGCLineStyle)) {
xmask |= GCLineStyle;
xgval.line_style = gval.fLineStyle; // ident mapping
}
if ((mask & kGCCapStyle)) {
xmask |= GCCapStyle;
xgval.cap_style = gval.fCapStyle; // ident mapping
}
if ((mask & kGCJoinStyle)) {
xmask |= GCJoinStyle;
xgval.join_style = gval.fJoinStyle; // ident mapping
}
if ((mask & kGCFillStyle)) {
xmask |= GCFillStyle;
xgval.fill_style = gval.fFillStyle; // ident mapping
}
if ((mask & kGCFillRule)) {
xmask |= GCFillRule;
xgval.fill_rule = gval.fFillRule; // ident mapping
}
if ((mask & kGCTile)) {
xmask |= GCTile;
xgval.tile = (Pixmap) gval.fTile;
}
if ((mask & kGCStipple)) {
xmask |= GCStipple;
xgval.stipple = (Pixmap) gval.fStipple;
}
if ((mask & kGCTileStipXOrigin)) {
xmask |= GCTileStipXOrigin;
xgval.ts_x_origin = gval.fTsXOrigin;
}
if ((mask & kGCTileStipYOrigin)) {
xmask |= GCTileStipYOrigin;
xgval.ts_y_origin = gval.fTsYOrigin;
}
if ((mask & kGCFont)) {
if (!fHasXft) {
xmask |= GCFont;
xgval.font = (Font) gval.fFont;
}
}
if ((mask & kGCSubwindowMode)) {
xmask |= GCSubwindowMode;
xgval.subwindow_mode = gval.fSubwindowMode; // ident mapping
}
if ((mask & kGCGraphicsExposures)) {
xmask |= GCGraphicsExposures;
xgval.graphics_exposures = (Bool) gval.fGraphicsExposures;
}
if ((mask & kGCClipXOrigin)) {
xmask |= GCClipXOrigin;
xgval.clip_x_origin = gval.fClipXOrigin;
}
if ((mask & kGCClipYOrigin)) {
xmask |= GCClipYOrigin;
xgval.clip_y_origin = gval.fClipYOrigin;
}
if ((mask & kGCClipMask)) {
xmask |= GCClipMask;
xgval.clip_mask = (Pixmap) gval.fClipMask;
}
if ((mask & kGCDashOffset)) {
xmask |= GCDashOffset;
xgval.dash_offset = gval.fDashOffset;
}
if ((mask & kGCDashList)) {
xmask |= GCDashList;
xgval.dashes = gval.fDashes[0];
}
if ((mask & kGCArcMode)) {
xmask |= GCArcMode;
xgval.arc_mode = gval.fArcMode; // ident mapping
}
} else {
// map XValues to GCValues_t
Mask_t mask = 0;
if ((xmask & GCFunction)) {
mask |= kGCFunction;
gval.fFunction = (EGraphicsFunction) xgval.function; // ident mapping
}
if ((xmask & GCPlaneMask)) {
mask |= kGCPlaneMask;
gval.fPlaneMask = xgval.plane_mask;
}
if ((xmask & GCForeground)) {
mask |= kGCForeground;
gval.fForeground = xgval.foreground;
}
if ((xmask & GCBackground)) {
mask |= kGCBackground;
gval.fBackground = xgval.background;
}
if ((xmask & GCLineWidth)) {
mask |= kGCLineWidth;
gval.fLineWidth = xgval.line_width;
}
if ((xmask & GCLineStyle)) {
mask |= kGCLineStyle;
gval.fLineStyle = xgval.line_style; // ident mapping
}
if ((xmask & GCCapStyle)) {
mask |= kGCCapStyle;
gval.fCapStyle = xgval.cap_style; // ident mapping
}
if ((xmask & GCJoinStyle)) {
mask |= kGCJoinStyle;
gval.fJoinStyle = xgval.join_style; // ident mapping
}
if ((xmask & GCFillStyle)) {
mask |= kGCFillStyle;
gval.fFillStyle = xgval.fill_style; // ident mapping
}
if ((xmask & GCFillRule)) {
mask |= kGCFillRule;
gval.fFillRule = xgval.fill_rule; // ident mapping
}
if ((xmask & GCTile)) {
mask |= kGCTile;
gval.fTile = (Pixmap_t) xgval.tile;
}
if ((xmask & GCStipple)) {
mask |= kGCStipple;
gval.fStipple = (Pixmap_t) xgval.stipple;
}
if ((xmask & GCTileStipXOrigin)) {
mask |= kGCTileStipXOrigin;
gval.fTsXOrigin = xgval.ts_x_origin;
}
if ((xmask & GCTileStipYOrigin)) {
mask |= kGCTileStipYOrigin;
gval.fTsYOrigin = xgval.ts_y_origin;
}
if ((xmask & GCFont)) {
mask |= kGCFont;
gval.fFont = (FontH_t) xgval.font;
}
if ((xmask & GCSubwindowMode)) {
mask |= kGCSubwindowMode;
gval.fSubwindowMode = xgval.subwindow_mode; // ident mapping
}
if ((xmask & GCGraphicsExposures)) {
mask |= kGCGraphicsExposures;
gval.fGraphicsExposures = (Bool_t) xgval.graphics_exposures;
}
if ((xmask & GCClipXOrigin)) {
mask |= kGCClipXOrigin;
gval.fClipXOrigin = xgval.clip_x_origin;
}
if ((xmask & GCClipYOrigin)) {
mask |= kGCClipYOrigin;
gval.fClipYOrigin = xgval.clip_y_origin;
}
if ((xmask & GCClipMask)) {
mask |= kGCClipMask;
gval.fClipMask = (Pixmap_t) xgval.clip_mask;
}
if ((xmask & GCDashOffset)) {
mask |= kGCDashOffset;
gval.fDashOffset = xgval.dash_offset;
}
if ((xmask & GCDashList)) {
mask |= kGCDashList;
gval.fDashes[0] = xgval.dashes;
gval.fDashLen = 1;
}
if ((xmask & GCArcMode)) {
mask |= kGCArcMode;
gval.fArcMode = xgval.arc_mode; // ident mapping
}
gval.fMask = mask;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Get window attributes and return filled in attributes structure.
void TGX11::GetWindowAttributes(Window_t id, WindowAttributes_t &attr)
{
if (!id) return;
XWindowAttributes xattr;
XGetWindowAttributes((Display*)fDisplay, id, &xattr);
attr.fX = xattr.x;
attr.fY = xattr.y;
attr.fWidth = xattr.width;
attr.fHeight = xattr.height;
attr.fBorderWidth = xattr.border_width;
attr.fDepth = xattr.depth;
attr.fVisual = xattr.visual;
attr.fRoot = (Window_t) xattr.root;
if (xattr.c_class == InputOutput) attr.fClass = kInputOutput;
if (xattr.c_class == InputOnly) attr.fClass = kInputOnly;
attr.fBitGravity = xattr.bit_gravity; // assume ident mapping (rdm)
attr.fWinGravity = xattr.win_gravity; // assume ident mapping (rdm)
if (xattr.backing_store == NotUseful) attr.fBackingStore = kNotUseful;
if (xattr.backing_store == WhenMapped) attr.fBackingStore = kWhenMapped;
if (xattr.backing_store == Always) attr.fBackingStore = kAlways;
attr.fBackingPlanes = xattr.backing_planes;
attr.fBackingPixel = xattr.backing_pixel;
attr.fSaveUnder = (Bool_t) xattr.save_under;
if ((Window) id == fRootWin)
attr.fColormap = (Colormap_t) fColormap;
else
attr.fColormap = (Colormap_t) xattr.colormap;
attr.fMapInstalled = (Bool_t) xattr.map_installed;
attr.fMapState = xattr.map_state; // ident mapping
attr.fAllEventMasks = xattr.all_event_masks; // not ident, but not used by GUI classes
attr.fYourEventMask = xattr.your_event_mask; // not ident, but not used by GUI classes
attr.fDoNotPropagateMask = xattr.do_not_propagate_mask;
attr.fOverrideRedirect = (Bool_t) xattr.override_redirect;
attr.fScreen = xattr.screen;
}
////////////////////////////////////////////////////////////////////////////////
/// Open connection to display server (if such a thing exist on the
/// current platform). On X11 this method returns on success the X
/// display socket descriptor (> 0), 0 in case of batch mode and < 0
/// in case of failure (cannot connect to display dpyName). It also
/// initializes the TGX11 class via Init(). Called from TGClient ctor.
Int_t TGX11::OpenDisplay(const char *dpyName)
{
#ifdef _REENTRANT
// In some cases there can be problems due to XInitThreads, like when
// using Qt, so we allow for it to be turned off
if (gEnv->GetValue("X11.XInitThread", 1)) {
// Must be very first call before any X11 call !!
if (!XInitThreads())
Warning("OpenDisplay", "system has no X11 thread support");
}
#endif
Display *dpy;
if (!(dpy = XOpenDisplay(dpyName)))
return -1;
// Set custom X11 error handlers
XSetErrorHandler(RootX11ErrorHandler);
XSetIOErrorHandler(RootX11IOErrorHandler);
if (gEnv->GetValue("X11.Sync", 0))
XSynchronize(dpy, 1);
// Init the GX11 class, sets a.o. fDisplay.
if (!Init(dpy))
return -1;
return ConnectionNumber(dpy);
}
////////////////////////////////////////////////////////////////////////////////
/// Close connection to display server.
void TGX11::CloseDisplay()
{
XCloseDisplay((Display*)fDisplay);
fDisplay = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns handle to display (might be useful in some cases where
/// direct X11 manipulation outside of TVirtualX is needed, e.g. GL
/// interface).
Display_t TGX11::GetDisplay() const
{
return (Display_t) fDisplay;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns handle to visual (might be useful in some cases where
/// direct X11 manipulation outside of TVirtualX is needed, e.g. GL
/// interface).
Visual_t TGX11::GetVisual() const
{
return (Visual_t) fVisual;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns handle to colormap (might be useful in some cases where
/// direct X11 manipulation outside of TVirtualX is needed, e.g. GL
/// interface).
Colormap_t TGX11::GetColormap() const
{
return (Colormap_t) fColormap;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns screen number (might be useful in some cases where
/// direct X11 manipulation outside of TVirtualX is needed, e.g. GL
/// interface).
Int_t TGX11::GetScreen() const
{
return fScreenNumber;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns depth of screen (number of bit planes). Equivalent to
/// GetPlanes().
Int_t TGX11::GetDepth() const
{
return fDepth;
}
////////////////////////////////////////////////////////////////////////////////
/// Return atom handle for atom_name. If it does not exist
/// create it if only_if_exist is false. Atoms are used to communicate
/// between different programs (i.e. window manager) via the X server.
Atom_t TGX11::InternAtom(const char *atom_name, Bool_t only_if_exist)
{
Atom a = XInternAtom((Display*)fDisplay, (char *)atom_name, (Bool)only_if_exist);
if (a == None) return kNone;
return (Atom_t) a;
}
////////////////////////////////////////////////////////////////////////////////
/// Return handle to the default root window created when calling
/// XOpenDisplay().
Window_t TGX11::GetDefaultRootWindow() const
{
return (Window_t) fRootWin;
}
////////////////////////////////////////////////////////////////////////////////
/// Return the parent of the window.
Window_t TGX11::GetParent(Window_t id) const
{
if (!id) return (Window_t)0;
Window root, parent;
Window *children = 0;
UInt_t nchildren;
XQueryTree((Display*)fDisplay, (Window) id, &root, &parent, &children, &nchildren);
if (children) XFree(children);
return (Window_t) parent;
}
////////////////////////////////////////////////////////////////////////////////
/// Load font and query font. If font is not found 0 is returned,
/// otherwise an opaque pointer to the FontStruct_t.
/// Free the loaded font using DeleteFont().
FontStruct_t TGX11::LoadQueryFont(const char *font_name)
{
XFontStruct *fs = XLoadQueryFont((Display*)fDisplay, (char *)font_name);
return (FontStruct_t) fs;
}
////////////////////////////////////////////////////////////////////////////////
/// Return handle to font described by font structure.
FontH_t TGX11::GetFontHandle(FontStruct_t fs)
{
if (fs) {
XFontStruct *fss = (XFontStruct *)fs;
return fss->fid;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Explicitly delete font structure obtained with LoadQueryFont().
void TGX11::DeleteFont(FontStruct_t fs)
{
if (fDisplay) XFreeFont((Display*)fDisplay, (XFontStruct *) fs);
}
////////////////////////////////////////////////////////////////////////////////
/// Create a graphics context using the values set in gval (but only for
/// those entries that are in the mask).
GContext_t TGX11::CreateGC(Drawable_t id, GCValues_t *gval)
{
RXGCValues xgval;
ULong_t xmask = 0;
if (gval)
MapGCValues(*gval, xmask, xgval);
if (!id || ((Drawable) id == fRootWin))
id = (Drawable_t) fVisRootWin;
GC gc = XCreateGC((Display*)fDisplay, (Drawable) id, xmask, &xgval);
if (gval && (gval->fMask & kGCFont))
MapGCFont((GContext_t)gc, gval->fFont);