27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
29 #include <X11/cursorfont.h>
30 #include <X11/keysym.h>
46 struct MWMHintsProperty_t {
49 Handle_t fDecorations;
55 const ULong_t kMWMHintsFunctions = BIT(0);
56 const ULong_t kMWMHintsDecorations = BIT(1);
57 const ULong_t kMWMHintsInputMode = BIT(2);
59 const Int_t kPropMotifWMHintsElements = 4;
60 const Int_t kPropMWMHintElements = kPropMotifWMHintsElements;
65 struct KeySymbolMap_t {
73 static KeySymbolMap_t gKeyMap[] = {
74 { XK_Escape, kKey_Escape },
76 #ifndef XK_ISO_Left_Tab
77 { 0xFE20, kKey_Backtab },
79 { XK_ISO_Left_Tab, kKey_Backtab },
81 { XK_BackSpace, kKey_Backspace },
82 { XK_Return, kKey_Return },
83 { XK_Insert, kKey_Insert },
84 { XK_Delete, kKey_Delete },
85 { XK_Clear, kKey_Delete },
86 { XK_Pause, kKey_Pause },
87 { XK_Print, kKey_Print },
88 { 0x1005FF60, kKey_SysReq },
89 { 0x1007ff00, kKey_SysReq },
90 { XK_Home, kKey_Home },
92 { XK_Left, kKey_Left },
94 { XK_Right, kKey_Right },
95 { XK_Down, kKey_Down },
96 { XK_Prior, kKey_Prior },
97 { XK_Next, kKey_Next },
98 { XK_Shift_L, kKey_Shift },
99 { XK_Shift_R, kKey_Shift },
100 { XK_Shift_Lock, kKey_Shift },
101 { XK_Control_L, kKey_Control },
102 { XK_Control_R, kKey_Control },
103 { XK_Meta_L, kKey_Meta },
104 { XK_Meta_R, kKey_Meta },
105 { XK_Alt_L, kKey_Alt },
106 { XK_Alt_R, kKey_Alt },
107 { XK_Caps_Lock, kKey_CapsLock },
108 { XK_Num_Lock, kKey_NumLock },
109 { XK_Scroll_Lock, kKey_ScrollLock },
110 { XK_KP_Space, kKey_Space },
111 { XK_KP_Tab, kKey_Tab },
112 { XK_KP_Enter, kKey_Enter },
113 { XK_KP_F1, kKey_F1 },
114 { XK_KP_F2, kKey_F2 },
115 { XK_KP_F3, kKey_F3 },
116 { XK_KP_F4, kKey_F4 },
117 { XK_KP_Home, kKey_Home },
118 { XK_KP_Left, kKey_Left },
119 { XK_KP_Up, kKey_Up },
120 { XK_KP_Right, kKey_Right },
121 { XK_KP_Down, kKey_Down },
122 { XK_KP_Prior, kKey_Prior },
123 { XK_KP_Page_Up, kKey_PageUp },
124 { XK_KP_Next, kKey_Next },
125 { XK_KP_Page_Down, kKey_PageDown },
126 { XK_KP_End, kKey_End },
127 { XK_KP_Begin, kKey_Home },
128 { XK_KP_Insert, kKey_Insert },
129 { XK_KP_Delete, kKey_Delete },
130 { XK_KP_Equal, kKey_Equal },
131 { XK_KP_Multiply, kKey_Asterisk },
132 { XK_KP_Add, kKey_Plus },
133 { XK_KP_Separator, kKey_Comma },
134 { XK_KP_Subtract, kKey_Minus },
135 { XK_KP_Decimal, kKey_Period },
136 { XK_KP_Divide, kKey_Slash },
140 struct RXGCValues:XGCValues{};
141 struct RXColor:XColor{};
142 struct RXpmAttributes:XpmAttributes{};
143 struct RXSetWindowAttributes:XSetWindowAttributes{};
144 struct RVisual:Visual{};
148 inline void SplitLong(Long_t ll, Long_t &i1, Long_t &i2)
150 union { Long_t l; Int_t i[2]; } conv;
159 inline void AsmLong(Long_t i1, Long_t i2, Long_t &ll)
161 union { Long_t l; Int_t i[2]; } conv;
163 conv.i[0] = (Int_t) i1;
164 conv.i[1] = (Int_t) i2;
171 static Int_t RootX11ErrorHandler(Display *disp, XErrorEvent *err)
174 XGetErrorText(disp, err->error_code, msg, 80);
177 if (gDebug == (Long_t)gVirtualX) {
178 gSystem->ProcessEvents();
179 ::Error(
"RootX11ErrorHandler",
"%s (XID: %u, XREQ: %u)", msg,
180 (UInt_t)err->resourceid, err->request_code);
186 if (!err->resourceid)
return 0;
188 TObject *w = (TObject *)gROOT->ProcessLineFast(Form(
"gClient ? gClient->GetWindowById(%lu) : 0",
189 (ULong_t)err->resourceid));
192 ::Error(
"RootX11ErrorHandler",
"%s (XID: %u, XREQ: %u)", msg,
193 (UInt_t)err->resourceid, err->request_code);
195 ::Error(
"RootX11ErrorHandler",
"%s (%s XID: %u, XREQ: %u)", msg, w->ClassName(),
196 (UInt_t)err->resourceid, err->request_code);
199 if (TROOT::Initialized()) {
210 static Int_t RootX11IOErrorHandler(Display *)
212 ::Error(
"RootX11IOErrorHandler",
"fatal X11 error (connection to server lost?!)");
213 fprintf(stderr,
"\n**** Save data and exit application ****\n\n");
215 if (gXDisplay && gSystem) {
216 gSystem->RemoveFileHandler(gXDisplay);
217 SafeDelete(gXDisplay);
219 if (TROOT::Initialized()) {
230 void TGX11::MapWindow(Window_t
id)
234 XMapWindow((Display*)fDisplay, (Window)
id);
240 void TGX11::MapSubwindows(Window_t
id)
244 XMapSubwindows((Display*)fDisplay, (Window)
id);
250 void TGX11::MapRaised(Window_t
id)
254 XMapRaised((Display*)fDisplay, (Window)
id);
260 void TGX11::UnmapWindow(Window_t
id)
264 XUnmapWindow((Display*)fDisplay, (Window)
id);
270 void TGX11::DestroyWindow(Window_t
id)
274 XDestroyWindow((Display*)fDisplay, (Window)
id);
280 void TGX11::DestroySubwindows(Window_t
id)
284 XDestroySubwindows((Display*)fDisplay, (Window)
id);
290 void TGX11::RaiseWindow(Window_t
id)
294 XRaiseWindow((Display*)fDisplay, (Window)
id);
300 void TGX11::LowerWindow(Window_t
id)
304 XLowerWindow((Display*)fDisplay, (Window)
id);
310 void TGX11::MoveWindow(Window_t
id, Int_t x, Int_t y)
314 XMoveWindow((Display*)fDisplay, (Window)
id, x, y);
320 void TGX11::MoveResizeWindow(Window_t
id, Int_t x, Int_t y, UInt_t w, UInt_t h)
324 XMoveResizeWindow((Display*)fDisplay, (Window)
id, x, y, w, h);
330 void TGX11::ResizeWindow(Window_t
id, UInt_t w, UInt_t h)
335 if (w >= (UInt_t)INT_MAX || h >= (UInt_t)INT_MAX)
337 XResizeWindow((Display*)fDisplay, (Window)
id, w, h);
343 void TGX11::IconifyWindow(Window_t
id)
347 XIconifyWindow((Display*)fDisplay, (Window)
id, fScreenNumber);
353 void TGX11::ReparentWindow(Window_t
id, Window_t pid, Int_t x, Int_t y)
357 XReparentWindow((Display*)fDisplay, (Window)
id, (Window) pid, x, y);
363 void TGX11::SetWindowBackground(Window_t
id, ULong_t color)
367 XSetWindowBackground((Display*)fDisplay, (Window)
id, color);
373 void TGX11::SetWindowBackgroundPixmap(Window_t
id, Pixmap_t pxm)
377 XSetWindowBackgroundPixmap((Display*)fDisplay, (Window)
id, (Pixmap) pxm);
383 Window_t TGX11::CreateWindow(Window_t parent, Int_t x, Int_t y,
384 UInt_t w, UInt_t h, UInt_t border,
385 Int_t depth, UInt_t clss,
386 void *visual, SetWindowAttributes_t *attr, UInt_t)
388 RXSetWindowAttributes xattr;
392 MapSetWindowAttributes(attr, xmask, xattr);
398 if (fColormap && !(xmask & CWColormap)) {
400 xattr.colormap = fColormap;
402 if ((Window)parent == fRootWin && fRootWin != fVisRootWin) {
403 xmask |= CWBorderPixel;
404 xattr.border_pixel = fBlackPixel;
407 return (Window_t) XCreateWindow((Display*)fDisplay, (Window) parent, x, y,
408 w, h, border, depth, clss, (Visual*)visual,
415 void TGX11::MapEventMask(UInt_t &emask, UInt_t &xemask, Bool_t tox)
418 Long_t lxemask = NoEventMask;
419 if ((emask & kKeyPressMask))
420 lxemask |= KeyPressMask;
421 if ((emask & kKeyReleaseMask))
422 lxemask |= KeyReleaseMask;
423 if ((emask & kButtonPressMask))
424 lxemask |= ButtonPressMask;
425 if ((emask & kButtonReleaseMask))
426 lxemask |= ButtonReleaseMask;
427 if ((emask & kPointerMotionMask))
428 lxemask |= PointerMotionMask;
429 if ((emask & kButtonMotionMask))
430 lxemask |= ButtonMotionMask;
431 if ((emask & kExposureMask))
432 lxemask |= ExposureMask;
433 if ((emask & kStructureNotifyMask))
434 lxemask |= StructureNotifyMask;
435 if ((emask & kEnterWindowMask))
436 lxemask |= EnterWindowMask;
437 if ((emask & kLeaveWindowMask))
438 lxemask |= LeaveWindowMask;
439 if ((emask & kFocusChangeMask))
440 lxemask |= FocusChangeMask;
441 if ((emask & kOwnerGrabButtonMask))
442 lxemask |= OwnerGrabButtonMask;
443 if ((emask & kColormapChangeMask))
444 lxemask |= ColormapChangeMask;
445 xemask = (UInt_t)lxemask;
448 if ((xemask & KeyPressMask))
449 emask |= kKeyPressMask;
450 if ((xemask & KeyReleaseMask))
451 emask |= kKeyReleaseMask;
452 if ((xemask & ButtonPressMask))
453 emask |= kButtonPressMask;
454 if ((xemask & ButtonReleaseMask))
455 emask |= kButtonReleaseMask;
456 if ((xemask & PointerMotionMask))
457 emask |= kPointerMotionMask;
458 if ((xemask & ButtonMotionMask))
459 emask |= kButtonMotionMask;
460 if ((xemask & ExposureMask))
461 emask |= kExposureMask;
462 if ((xemask & StructureNotifyMask))
463 emask |= kStructureNotifyMask;
464 if ((xemask & EnterWindowMask))
465 emask |= kEnterWindowMask;
466 if ((xemask & LeaveWindowMask))
467 emask |= kLeaveWindowMask;
468 if ((xemask & FocusChangeMask))
469 emask |= kFocusChangeMask;
470 if ((xemask & OwnerGrabButtonMask))
471 emask |= kOwnerGrabButtonMask;
472 if ((xemask & ColormapChangeMask))
473 emask |= kColormapChangeMask;
480 void TGX11::MapSetWindowAttributes(SetWindowAttributes_t *attr,
481 ULong_t &xmask, RXSetWindowAttributes &xattr)
483 Mask_t mask = attr->fMask;
486 if ((mask & kWABackPixmap)) {
487 xmask |= CWBackPixmap;
488 if (attr->fBackgroundPixmap == kNone)
489 xattr.background_pixmap = None;
490 else if (attr->fBackgroundPixmap == kParentRelative)
491 xattr.background_pixmap = ParentRelative;
493 xattr.background_pixmap = (Pixmap)attr->fBackgroundPixmap;
495 if ((mask & kWABackPixel)) {
496 xmask |= CWBackPixel;
497 xattr.background_pixel = attr->fBackgroundPixel;
499 if ((mask & kWABorderPixmap)) {
500 xmask |= CWBorderPixmap;
501 xattr.border_pixmap = (Pixmap)attr->fBorderPixmap;
503 if ((mask & kWABorderPixel)) {
504 xmask |= CWBorderPixel;
505 xattr.border_pixel = attr->fBorderPixel;
507 if ((mask & kWABitGravity)) {
508 xmask |= CWBitGravity;
509 xattr.bit_gravity = attr->fBitGravity;
511 if ((mask & kWAWinGravity)) {
512 xmask |= CWWinGravity;
513 xattr.win_gravity = attr->fWinGravity;
515 if ((mask & kWABackingStore)) {
516 xmask |= CWBackingStore;
517 if (attr->fBackingStore == kNotUseful)
518 xattr.backing_store = NotUseful;
519 else if (attr->fBackingStore == kWhenMapped)
520 xattr.backing_store = WhenMapped;
521 else if (attr->fBackingStore == kAlways)
522 xattr.backing_store = Always;
524 xattr.backing_store = attr->fBackingStore;
526 if ((mask & kWABackingPlanes)) {
527 xmask |= CWBackingPlanes;
528 xattr.backing_planes = attr->fBackingPlanes;
530 if ((mask & kWABackingPixel)) {
531 xmask |= CWBackingPixel;
532 xattr.backing_pixel = attr->fBackingPixel;
534 if ((mask & kWAOverrideRedirect)) {
535 xmask |= CWOverrideRedirect;
536 xattr.override_redirect = attr->fOverrideRedirect;
538 if ((mask & kWASaveUnder)) {
539 xmask |= CWSaveUnder;
540 xattr.save_under = (Bool)attr->fSaveUnder;
542 if ((mask & kWAEventMask)) {
543 xmask |= CWEventMask;
544 UInt_t xmsk, msk = (UInt_t) attr->fEventMask;
545 MapEventMask(msk, xmsk, kTRUE);
546 xattr.event_mask = xmsk;
548 if ((mask & kWADontPropagate)) {
549 xmask |= CWDontPropagate;
550 xattr.do_not_propagate_mask = attr->fDoNotPropagateMask;
552 if ((mask & kWAColormap)) {
554 xattr.colormap = (Colormap)attr->fColormap;
556 if ((mask & kWACursor)) {
558 if (attr->fCursor == kNone)
561 xattr.cursor = (Cursor)attr->fCursor;
569 void TGX11::MapGCValues(GCValues_t &gval,
570 ULong_t &xmask, RXGCValues &xgval, Bool_t tox)
574 Mask_t mask = gval.fMask;
577 if ((mask & kGCFunction)) {
579 xgval.function = gval.fFunction;
581 if ((mask & kGCPlaneMask)) {
582 xmask |= GCPlaneMask;
583 xgval.plane_mask = gval.fPlaneMask;
585 if ((mask & kGCForeground)) {
586 xmask |= GCForeground;
587 xgval.foreground = gval.fForeground;
589 if ((mask & kGCBackground)) {
590 xmask |= GCBackground;
591 xgval.background = gval.fBackground;
593 if ((mask & kGCLineWidth)) {
594 xmask |= GCLineWidth;
595 xgval.line_width = gval.fLineWidth;
597 if ((mask & kGCLineStyle)) {
598 xmask |= GCLineStyle;
599 xgval.line_style = gval.fLineStyle;
601 if ((mask & kGCCapStyle)) {
603 xgval.cap_style = gval.fCapStyle;
605 if ((mask & kGCJoinStyle)) {
606 xmask |= GCJoinStyle;
607 xgval.join_style = gval.fJoinStyle;
609 if ((mask & kGCFillStyle)) {
610 xmask |= GCFillStyle;
611 xgval.fill_style = gval.fFillStyle;
613 if ((mask & kGCFillRule)) {
615 xgval.fill_rule = gval.fFillRule;
617 if ((mask & kGCTile)) {
619 xgval.tile = (Pixmap) gval.fTile;
621 if ((mask & kGCStipple)) {
623 xgval.stipple = (Pixmap) gval.fStipple;
625 if ((mask & kGCTileStipXOrigin)) {
626 xmask |= GCTileStipXOrigin;
627 xgval.ts_x_origin = gval.fTsXOrigin;
629 if ((mask & kGCTileStipYOrigin)) {
630 xmask |= GCTileStipYOrigin;
631 xgval.ts_y_origin = gval.fTsYOrigin;
633 if ((mask & kGCFont)) {
636 xgval.font = (Font) gval.fFont;
639 if ((mask & kGCSubwindowMode)) {
640 xmask |= GCSubwindowMode;
641 xgval.subwindow_mode = gval.fSubwindowMode;
643 if ((mask & kGCGraphicsExposures)) {
644 xmask |= GCGraphicsExposures;
645 xgval.graphics_exposures = (Bool) gval.fGraphicsExposures;
647 if ((mask & kGCClipXOrigin)) {
648 xmask |= GCClipXOrigin;
649 xgval.clip_x_origin = gval.fClipXOrigin;
651 if ((mask & kGCClipYOrigin)) {
652 xmask |= GCClipYOrigin;
653 xgval.clip_y_origin = gval.fClipYOrigin;
655 if ((mask & kGCClipMask)) {
657 xgval.clip_mask = (Pixmap) gval.fClipMask;
659 if ((mask & kGCDashOffset)) {
660 xmask |= GCDashOffset;
661 xgval.dash_offset = gval.fDashOffset;
663 if ((mask & kGCDashList)) {
665 xgval.dashes = gval.fDashes[0];
667 if ((mask & kGCArcMode)) {
669 xgval.arc_mode = gval.fArcMode;
676 if ((xmask & GCFunction)) {
678 gval.fFunction = (EGraphicsFunction) xgval.function;
680 if ((xmask & GCPlaneMask)) {
681 mask |= kGCPlaneMask;
682 gval.fPlaneMask = xgval.plane_mask;
684 if ((xmask & GCForeground)) {
685 mask |= kGCForeground;
686 gval.fForeground = xgval.foreground;
688 if ((xmask & GCBackground)) {
689 mask |= kGCBackground;
690 gval.fBackground = xgval.background;
692 if ((xmask & GCLineWidth)) {
693 mask |= kGCLineWidth;
694 gval.fLineWidth = xgval.line_width;
696 if ((xmask & GCLineStyle)) {
697 mask |= kGCLineStyle;
698 gval.fLineStyle = xgval.line_style;
700 if ((xmask & GCCapStyle)) {
702 gval.fCapStyle = xgval.cap_style;
704 if ((xmask & GCJoinStyle)) {
705 mask |= kGCJoinStyle;
706 gval.fJoinStyle = xgval.join_style;
708 if ((xmask & GCFillStyle)) {
709 mask |= kGCFillStyle;
710 gval.fFillStyle = xgval.fill_style;
712 if ((xmask & GCFillRule)) {
714 gval.fFillRule = xgval.fill_rule;
716 if ((xmask & GCTile)) {
718 gval.fTile = (Pixmap_t) xgval.tile;
720 if ((xmask & GCStipple)) {
722 gval.fStipple = (Pixmap_t) xgval.stipple;
724 if ((xmask & GCTileStipXOrigin)) {
725 mask |= kGCTileStipXOrigin;
726 gval.fTsXOrigin = xgval.ts_x_origin;
728 if ((xmask & GCTileStipYOrigin)) {
729 mask |= kGCTileStipYOrigin;
730 gval.fTsYOrigin = xgval.ts_y_origin;
732 if ((xmask & GCFont)) {
734 gval.fFont = (FontH_t) xgval.font;
736 if ((xmask & GCSubwindowMode)) {
737 mask |= kGCSubwindowMode;
738 gval.fSubwindowMode = xgval.subwindow_mode;
740 if ((xmask & GCGraphicsExposures)) {
741 mask |= kGCGraphicsExposures;
742 gval.fGraphicsExposures = (Bool_t) xgval.graphics_exposures;
744 if ((xmask & GCClipXOrigin)) {
745 mask |= kGCClipXOrigin;
746 gval.fClipXOrigin = xgval.clip_x_origin;
748 if ((xmask & GCClipYOrigin)) {
749 mask |= kGCClipYOrigin;
750 gval.fClipYOrigin = xgval.clip_y_origin;
752 if ((xmask & GCClipMask)) {
754 gval.fClipMask = (Pixmap_t) xgval.clip_mask;
756 if ((xmask & GCDashOffset)) {
757 mask |= kGCDashOffset;
758 gval.fDashOffset = xgval.dash_offset;
760 if ((xmask & GCDashList)) {
762 gval.fDashes[0] = xgval.dashes;
765 if ((xmask & GCArcMode)) {
767 gval.fArcMode = xgval.arc_mode;
776 void TGX11::GetWindowAttributes(Window_t
id, WindowAttributes_t &attr)
780 XWindowAttributes xattr;
782 XGetWindowAttributes((Display*)fDisplay,
id, &xattr);
786 attr.fWidth = xattr.width;
787 attr.fHeight = xattr.height;
788 attr.fBorderWidth = xattr.border_width;
789 attr.fDepth = xattr.depth;
790 attr.fVisual = xattr.visual;
791 attr.fRoot = (Window_t) xattr.root;
792 if (xattr.c_class == InputOutput) attr.fClass = kInputOutput;
793 if (xattr.c_class == InputOnly) attr.fClass = kInputOnly;
794 attr.fBitGravity = xattr.bit_gravity;
795 attr.fWinGravity = xattr.win_gravity;
796 if (xattr.backing_store == NotUseful) attr.fBackingStore = kNotUseful;
797 if (xattr.backing_store == WhenMapped) attr.fBackingStore = kWhenMapped;
798 if (xattr.backing_store == Always) attr.fBackingStore = kAlways;
799 attr.fBackingPlanes = xattr.backing_planes;
800 attr.fBackingPixel = xattr.backing_pixel;
801 attr.fSaveUnder = (Bool_t) xattr.save_under;
802 if ((Window)
id == fRootWin)
803 attr.fColormap = (Colormap_t) fColormap;
805 attr.fColormap = (Colormap_t) xattr.colormap;
806 attr.fMapInstalled = (Bool_t) xattr.map_installed;
807 attr.fMapState = xattr.map_state;
808 attr.fAllEventMasks = xattr.all_event_masks;
809 attr.fYourEventMask = xattr.your_event_mask;
810 attr.fDoNotPropagateMask = xattr.do_not_propagate_mask;
811 attr.fOverrideRedirect = (Bool_t) xattr.override_redirect;
812 attr.fScreen = xattr.screen;
822 Int_t TGX11::OpenDisplay(
const char *dpyName)
827 if (gEnv->GetValue(
"X11.XInitThread", 1)) {
830 Warning(
"OpenDisplay",
"system has no X11 thread support");
835 if (!(dpy = XOpenDisplay(dpyName)))
839 XSetErrorHandler(RootX11ErrorHandler);
840 XSetIOErrorHandler(RootX11IOErrorHandler);
842 if (gEnv->GetValue(
"X11.Sync", 0))
843 XSynchronize(dpy, 1);
849 return ConnectionNumber(dpy);
855 void TGX11::CloseDisplay()
857 XCloseDisplay((Display*)fDisplay);
866 Display_t TGX11::GetDisplay()
const
868 return (Display_t) fDisplay;
876 Visual_t TGX11::GetVisual()
const
878 return (Visual_t) fVisual;
886 Colormap_t TGX11::GetColormap()
const
888 return (Colormap_t) fColormap;
896 Int_t TGX11::GetScreen()
const
898 return fScreenNumber;
905 Int_t TGX11::GetDepth()
const
915 Atom_t TGX11::InternAtom(
const char *atom_name, Bool_t only_if_exist)
917 Atom a = XInternAtom((Display*)fDisplay, (
char *)atom_name, (Bool)only_if_exist);
919 if (a == None)
return kNone;
927 Window_t TGX11::GetDefaultRootWindow()
const
929 return (Window_t) fRootWin;
935 Window_t TGX11::GetParent(Window_t
id)
const
937 if (!
id)
return (Window_t)0;
940 Window *children = 0;
943 XQueryTree((Display*)fDisplay, (Window)
id, &root, &parent, &children, &nchildren);
945 if (children) XFree(children);
947 return (Window_t) parent;
956 FontStruct_t TGX11::LoadQueryFont(
const char *font_name)
958 XFontStruct *fs = XLoadQueryFont((Display*)fDisplay, (
char *)font_name);
959 return (FontStruct_t) fs;
965 FontH_t TGX11::GetFontHandle(FontStruct_t fs)
968 XFontStruct *fss = (XFontStruct *)fs;
977 void TGX11::DeleteFont(FontStruct_t fs)
979 if (fDisplay) XFreeFont((Display*)fDisplay, (XFontStruct *) fs);
986 GContext_t TGX11::CreateGC(Drawable_t
id, GCValues_t *gval)
992 MapGCValues(*gval, xmask, xgval);
994 if (!
id || ((Drawable)
id == fRootWin))
995 id = (Drawable_t) fVisRootWin;
997 GC gc = XCreateGC((Display*)fDisplay, (Drawable)
id, xmask, &xgval);
999 if (gval && (gval->fMask & kGCFont))
1000 MapGCFont((GContext_t)gc, gval->fFont);
1002 return (GContext_t) gc;
1008 void TGX11::ChangeGC(GContext_t gc, GCValues_t *gval)
1014 MapGCValues(*gval, xmask, xgval);
1016 XChangeGC((Display*)fDisplay, (GC) gc, xmask, &xgval);
1018 if (gval && (gval->fMask & kGCFont))
1019 MapGCFont((GContext_t)gc, gval->fFont);
1027 void TGX11::CopyGC(GContext_t org, GContext_t dest, Mask_t mask)
1039 MapGCValues(gval, xmask, xgval);
1041 XCopyGC((Display*)fDisplay, (GC) org, xmask, (GC) dest);
1047 void TGX11::DeleteGC(GContext_t gc)
1052 XFreeGC((Display*)fDisplay, (GC) gc);
1058 Cursor_t TGX11::CreateCursor(ECursor cursor)
1060 return (Cursor_t) fCursors[cursor];
1066 void TGX11::SetCursor(Window_t
id, Cursor_t curid)
1070 XDefineCursor((Display*)fDisplay, (Window)
id, (Cursor) curid);
1077 Pixmap_t TGX11::CreatePixmap(Drawable_t
id, UInt_t w, UInt_t h)
1079 return (Pixmap_t) XCreatePixmap((Display*)fDisplay, (Drawable) (
id ?
id : fRootWin), w, h, fDepth);
1086 Pixmap_t TGX11::CreatePixmap(Drawable_t
id,
const char *bitmap,
1087 UInt_t width, UInt_t height, ULong_t forecolor, ULong_t backcolor,
1090 return (Pixmap_t) XCreatePixmapFromBitmapData((Display*)fDisplay, (
id ?
id : fRootWin), (
char *)bitmap,
1091 width, height, forecolor, backcolor, depth);
1097 Pixmap_t TGX11::CreateBitmap(Drawable_t
id,
const char *bitmap,
1098 UInt_t width, UInt_t height)
1100 return (Pixmap_t) XCreateBitmapFromData((Display*)fDisplay, (
id ?
id : fRootWin), (
char *)bitmap,
1107 void TGX11::DeletePixmap(Pixmap_t pmap)
1109 if (fDisplay) XFreePixmap((Display*)fDisplay, (Pixmap) pmap);
1116 void TGX11::MapPictureAttributes(PictureAttributes_t &attr, RXpmAttributes &xpmattr,
1121 Mask_t mask = attr.fMask;
1124 if ((mask & kPAColormap)) {
1125 xmask |= XpmColormap;
1126 xpmattr.colormap = (Colormap)attr.fColormap;
1128 if ((mask & kPADepth)) {
1130 xpmattr.depth = attr.fDepth;
1132 if ((mask & kPASize)) {
1134 xpmattr.width = attr.fWidth;
1135 xpmattr.height = attr.fHeight;
1137 if ((mask & kPAHotspot)) {
1138 xmask |= XpmHotspot;
1139 xpmattr.x_hotspot = attr.fXHotspot;
1140 xpmattr.y_hotspot = attr.fYHotspot;
1142 if ((mask & kPAReturnPixels)) {
1143 xmask |= XpmReturnPixels;
1145 xpmattr.npixels = 0;
1147 if ((mask & kPACloseness)) {
1148 xmask |= XpmCloseness;
1149 xpmattr.closeness = attr.fCloseness;
1151 xpmattr.valuemask = xmask;
1153 ULong_t xmask = xpmattr.valuemask;
1159 if ((xmask & XpmColormap)) {
1160 mask |= kPAColormap;
1161 attr.fColormap = (Colormap_t)xpmattr.colormap;
1163 attr.fDepth = xpmattr.depth;
1165 if ((xmask & XpmSize)) {
1167 attr.fWidth = xpmattr.width;
1168 attr.fHeight = xpmattr.height;
1170 if ((xmask & XpmHotspot)) {
1172 attr.fXHotspot = xpmattr.x_hotspot;
1173 attr.fYHotspot = xpmattr.y_hotspot;
1175 if ((xmask & XpmReturnPixels)) {
1176 mask |= kPAReturnPixels;
1177 if (xpmattr.npixels) {
1178 attr.fPixels =
new ULong_t[xpmattr.npixels];
1179 for (UInt_t i = 0; i < xpmattr.npixels; i++)
1180 attr.fPixels[i] = xpmattr.pixels[i];
1181 attr.fNpixels = xpmattr.npixels;
1184 if ((xmask & XpmCloseness)) {
1185 mask |= kPACloseness;
1186 attr.fCloseness = xpmattr.closeness;
1198 Bool_t TGX11::CreatePictureFromFile(Drawable_t
id,
const char *filename,
1199 Pixmap_t &pict, Pixmap_t &pict_mask,
1200 PictureAttributes_t &attr)
1202 if (strstr(filename,
".gif") || strstr(filename,
".GIF")) {
1203 pict = ReadGIF(0, 0, filename,
id);
1205 attr.fDepth = fDepth;
1207 GetWindowSize(pict, dummy, dummy, attr.fWidth, attr.fHeight);
1212 RXpmAttributes xpmattr;
1214 MapPictureAttributes(attr, xpmattr);
1217 if ((Drawable)
id == fRootWin && fRootWin != fVisRootWin) {
1218 xpmattr.valuemask |= XpmDepth;
1219 xpmattr.depth = fDepth;
1222 Int_t res = XpmReadFileToPixmap((Display*)fDisplay, (
id ?
id : fRootWin), (
char*)filename,
1223 (Pixmap*)&pict, (Pixmap*)&pict_mask, &xpmattr);
1225 MapPictureAttributes(attr, xpmattr, kFALSE);
1226 XpmFreeAttributes(&xpmattr);
1228 if (res == XpmSuccess || res == XpmColorError)
1232 XFreePixmap((Display*)fDisplay, (Pixmap)pict);
1236 XFreePixmap((Display*)fDisplay, (Pixmap)pict_mask);
1240 Error(
"CreatePictureFromFile",
"cannot get picture, not compiled with Xpm");
1251 Bool_t TGX11::CreatePictureFromData(Drawable_t
id,
char **data, Pixmap_t &pict,
1252 Pixmap_t &pict_mask, PictureAttributes_t &attr)
1255 RXpmAttributes xpmattr;
1257 MapPictureAttributes(attr, xpmattr);
1260 if ((Drawable)
id == fRootWin && fRootWin != fVisRootWin) {
1261 xpmattr.valuemask |= XpmDepth;
1262 xpmattr.depth = fDepth;
1265 Int_t res = XpmCreatePixmapFromData((Display*)fDisplay, (
id ?
id : fRootWin), data, (Pixmap*)&pict,
1266 (Pixmap*)&pict_mask, &xpmattr);
1268 MapPictureAttributes(attr, xpmattr, kFALSE);
1269 XpmFreeAttributes(&xpmattr);
1271 if (res == XpmSuccess || res == XpmColorError)
1275 XFreePixmap((Display*)fDisplay, (Pixmap)pict);
1279 XFreePixmap((Display*)fDisplay, (Pixmap)pict_mask);
1283 Error(
"CreatePictureFromData",
"cannot get picture, not compiled with Xpm");
1293 Bool_t TGX11::ReadPictureDataFromFile(
const char *filename,
char ***ret_data)
1296 if (XpmReadFileToData((
char*)filename, ret_data) == XpmSuccess)
1299 Error(
"ReadPictureFromDataFile",
"cannot get picture, not compiled with Xpm");
1307 void TGX11::DeletePictureData(
void *data)
1322 void TGX11::SetDashes(GContext_t gc, Int_t offset,
const char *dash_list, Int_t n)
1324 XSetDashes((Display*)fDisplay, (GC) gc, offset, (
char *)dash_list, n);
1330 void TGX11::MapColorStruct(ColorStruct_t *color, RXColor &xcolor)
1332 xcolor.pixel = color->fPixel;
1333 xcolor.red = color->fRed;
1334 xcolor.green = color->fGreen;
1335 xcolor.blue = color->fBlue;
1336 xcolor.flags = color->fMask;
1346 Bool_t TGX11::ParseColor(Colormap_t cmap,
const char *cname, ColorStruct_t &color)
1350 if (XParseColor((Display*)fDisplay, (Colormap)cmap, (
char *)cname, &xc)) {
1352 color.fRed = xc.red;
1353 color.fGreen = xc.green;
1354 color.fBlue = xc.blue;
1355 color.fMask = kDoRed | kDoGreen | kDoBlue;
1366 Bool_t TGX11::AllocColor(Colormap_t cmap, ColorStruct_t &color)
1370 MapColorStruct(&color, xc);
1373 if (AllocColor((Colormap)cmap, &xc)) {
1374 color.fPixel = xc.pixel;
1386 void TGX11::QueryColor(Colormap_t cmap, ColorStruct_t &color)
1390 xc.pixel = color.fPixel;
1395 XQueryColor((Display*)fDisplay, (Colormap)cmap, &xc);
1398 color.fRed = xc.red;
1399 color.fGreen = xc.green;
1400 color.fBlue = xc.blue;
1406 void TGX11::FreeColor(Colormap_t cmap, ULong_t pixel)
1409 XFreeColors((Display*)fDisplay, (Colormap)cmap, &pixel, 1, 0);
1415 Int_t TGX11::EventsPending()
1417 if (!fDisplay)
return 0;
1418 return XPending((Display*)fDisplay);
1426 void TGX11::NextEvent(Event_t &event)
1428 XNextEvent((Display*)fDisplay, (XEvent*)fXEvent);
1431 MapEvent(event, fXEvent, kFALSE);
1437 void TGX11::MapModifierState(UInt_t &state, UInt_t &xstate, Bool_t tox)
1441 if ((state & kKeyShiftMask))
1442 xstate |= ShiftMask;
1443 if ((state & kKeyLockMask))
1445 if ((state & kKeyControlMask))
1446 xstate |= ControlMask;
1447 if ((state & kKeyMod1Mask))
1449 if ((state & kKeyMod2Mask))
1451 if ((state & kKeyMod3Mask))
1453 if ((state & kKeyMod4Mask))
1455 if ((state & kKeyMod5Mask))
1457 if ((state & kButton1Mask))
1458 xstate |= Button1Mask;
1459 if ((state & kButton2Mask))
1460 xstate |= Button2Mask;
1461 if ((state & kButton3Mask))
1462 xstate |= Button3Mask;
1463 if ((state & kAnyModifier))
1464 xstate |= AnyModifier;
1467 if ((xstate & ShiftMask))
1468 state |= kKeyShiftMask;
1469 if ((xstate & LockMask))
1470 state |= kKeyLockMask;
1471 if ((xstate & ControlMask))
1472 state |= kKeyControlMask;
1473 if ((xstate & Mod1Mask))
1474 state |= kKeyMod1Mask;
1475 if ((xstate & Mod2Mask))
1476 state |= kKeyMod2Mask;
1477 if ((xstate & Mod3Mask))
1478 state |= kKeyMod3Mask;
1479 if ((xstate & Mod4Mask))
1480 state |= kKeyMod4Mask;
1481 if ((xstate & Mod5Mask))
1482 state |= kKeyMod5Mask;
1483 if ((xstate & Button1Mask))
1484 state |= kButton1Mask;
1485 if ((xstate & Button2Mask))
1486 state |= kButton2Mask;
1487 if ((xstate & Button3Mask))
1488 state |= kButton3Mask;
1489 if ((xstate & AnyModifier))
1490 state |= kAnyModifier;
1498 void TGX11::MapEvent(Event_t &ev,
void *xevi, Bool_t tox)
1500 XEvent &xev = *(XEvent *)xevi;
1505 if (ev.fType == kGKeyPress) xev.type = KeyPress;
1506 if (ev.fType == kKeyRelease) xev.type = KeyRelease;
1507 if (ev.fType == kButtonPress) xev.type = ButtonPress;
1508 if (ev.fType == kButtonRelease) xev.type = ButtonRelease;
1509 if (ev.fType == kMotionNotify) xev.type = MotionNotify;
1510 if (ev.fType == kEnterNotify) xev.type = EnterNotify;
1511 if (ev.fType == kLeaveNotify) xev.type = LeaveNotify;
1512 if (ev.fType == kFocusIn) xev.type = FocusIn;
1513 if (ev.fType == kFocusOut) xev.type = FocusOut;
1514 if (ev.fType == kExpose) xev.type = Expose;
1515 if (ev.fType == kConfigureNotify) xev.type = ConfigureNotify;
1516 if (ev.fType == kMapNotify) xev.type = MapNotify;
1517 if (ev.fType == kUnmapNotify) xev.type = UnmapNotify;
1518 if (ev.fType == kDestroyNotify) xev.type = DestroyNotify;
1519 if (ev.fType == kClientMessage) xev.type = ClientMessage;
1520 if (ev.fType == kSelectionClear) xev.type = SelectionClear;
1521 if (ev.fType == kSelectionRequest) xev.type = SelectionRequest;
1522 if (ev.fType == kSelectionNotify) xev.type = SelectionNotify;
1523 if (ev.fType == kColormapNotify) xev.type = ColormapNotify;
1525 xev.xany.window = (Window) ev.fWindow;
1526 xev.xany.send_event = (Bool) ev.fSendEvent;
1527 xev.xany.display = (Display*)fDisplay;
1529 if (ev.fType == kGKeyPress || ev.fType == kKeyRelease) {
1530 xev.xkey.time = (Time) ev.fTime;
1533 xev.xkey.x_root = ev.fXRoot;
1534 xev.xkey.y_root = ev.fYRoot;
1535 MapModifierState(ev.fState, xev.xkey.state, kTRUE);
1536 xev.xkey.keycode = ev.fCode;
1538 if (ev.fType == kSelectionNotify) {
1539 xev.xselection.time = (Time) ev.fTime;
1540 xev.xselection.requestor = (Window) ev.fUser[0];
1541 xev.xselection.selection = (Atom) ev.fUser[1];
1542 xev.xselection.target = (Atom) ev.fUser[2];
1543 xev.xselection.property = (Atom) ev.fUser[3];
1545 if (ev.fType == kClientMessage) {
1546 xev.xclient.message_type = ev.fHandle;
1547 xev.xclient.format = ev.fFormat;
1548 xev.xclient.data.l[0] = ev.fUser[0];
1549 if (
sizeof(ev.fUser[0]) > 4) {
1550 SplitLong(ev.fUser[1], xev.xclient.data.l[1], xev.xclient.data.l[3]);
1551 SplitLong(ev.fUser[2], xev.xclient.data.l[2], xev.xclient.data.l[4]);
1553 xev.xclient.data.l[1] = ev.fUser[1];
1554 xev.xclient.data.l[2] = ev.fUser[2];
1555 xev.xclient.data.l[3] = ev.fUser[3];
1556 xev.xclient.data.l[4] = ev.fUser[4];
1561 ev.fType = kOtherEvent;
1562 if (xev.type == KeyPress) ev.fType = kGKeyPress;
1563 if (xev.type == KeyRelease) ev.fType = kKeyRelease;
1564 if (xev.type == ButtonPress) ev.fType = kButtonPress;
1565 if (xev.type == ButtonRelease) ev.fType = kButtonRelease;
1566 if (xev.type == MotionNotify) ev.fType = kMotionNotify;
1567 if (xev.type == EnterNotify) ev.fType = kEnterNotify;
1568 if (xev.type == LeaveNotify) ev.fType = kLeaveNotify;
1569 if (xev.type == FocusIn) ev.fType = kFocusIn;
1570 if (xev.type == FocusOut) ev.fType = kFocusOut;
1571 if (xev.type == Expose) ev.fType = kExpose;
1572 if (xev.type == GraphicsExpose) ev.fType = kExpose;
1573 if (xev.type == ConfigureNotify) ev.fType = kConfigureNotify;
1574 if (xev.type == MapNotify) ev.fType = kMapNotify;
1575 if (xev.type == UnmapNotify) ev.fType = kUnmapNotify;
1576 if (xev.type == DestroyNotify) ev.fType = kDestroyNotify;
1577 if (xev.type == ClientMessage) ev.fType = kClientMessage;
1578 if (xev.type == SelectionClear) ev.fType = kSelectionClear;
1579 if (xev.type == SelectionRequest) ev.fType = kSelectionRequest;
1580 if (xev.type == SelectionNotify) ev.fType = kSelectionNotify;
1581 if (xev.type == ColormapNotify) ev.fType = kColormapNotify;
1583 ev.fWindow = (Window_t) xev.xany.window;
1584 ev.fSendEvent = xev.xany.send_event ? kTRUE : kFALSE;
1586 if (ev.fType == kGKeyPress || ev.fType == kKeyRelease) {
1587 ev.fTime = (Time_t) xev.xkey.time;
1590 ev.fXRoot = xev.xkey.x_root;
1591 ev.fYRoot = xev.xkey.y_root;
1592 MapModifierState(ev.fState, xev.xkey.state, kFALSE);
1593 ev.fCode = xev.xkey.keycode;
1594 ev.fUser[0] = xev.xkey.subwindow;
1596 if (ev.fType == kButtonPress || ev.fType == kButtonRelease) {
1597 ev.fTime = (Time_t) xev.xbutton.time;
1598 ev.fX = xev.xbutton.x;
1599 ev.fY = xev.xbutton.y;
1600 ev.fXRoot = xev.xbutton.x_root;
1601 ev.fYRoot = xev.xbutton.y_root;
1602 MapModifierState(ev.fState, xev.xbutton.state, kFALSE);
1603 ev.fCode = xev.xbutton.button;
1604 ev.fUser[0] = xev.xbutton.subwindow;
1606 if (ev.fType == kMotionNotify) {
1607 ev.fTime = (Time_t) xev.xmotion.time;
1608 ev.fX = xev.xmotion.x;
1609 ev.fY = xev.xmotion.y;
1610 ev.fXRoot = xev.xmotion.x_root;
1611 ev.fYRoot = xev.xmotion.y_root;
1612 MapModifierState(ev.fState, xev.xmotion.state, kFALSE);
1613 ev.fUser[0] = xev.xmotion.subwindow;
1615 if (ev.fType == kEnterNotify || ev.fType == kLeaveNotify) {
1616 ev.fTime = (Time_t) xev.xcrossing.time;
1617 ev.fX = xev.xcrossing.x;
1618 ev.fY = xev.xcrossing.y;
1619 ev.fXRoot = xev.xcrossing.x_root;
1620 ev.fYRoot = xev.xcrossing.y_root;
1621 ev.fCode = xev.xcrossing.mode;
1622 MapModifierState(ev.fState, xev.xcrossing.state, kFALSE);
1624 if (ev.fType == kFocusIn || ev.fType == kFocusOut) {
1626 ev.fCode = xev.xfocus.mode;
1627 ev.fState = xev.xfocus.detail;
1629 if (ev.fType == kExpose) {
1630 ev.fX = xev.xexpose.x;
1631 ev.fY = xev.xexpose.y;
1632 ev.fWidth = xev.xexpose.width;
1633 ev.fHeight = xev.xexpose.height;
1634 ev.fCount = xev.xexpose.count;
1636 if (ev.fType == kConfigureNotify) {
1637 ev.fX = xev.xconfigure.x;
1638 ev.fY = xev.xconfigure.y;
1639 ev.fWidth = xev.xconfigure.width;
1640 ev.fHeight = xev.xconfigure.height;
1642 if (ev.fType == kMapNotify || ev.fType == kUnmapNotify) {
1643 ev.fHandle = xev.xmap.window;
1645 if (ev.fType == kDestroyNotify) {
1646 ev.fHandle = xev.xdestroywindow.window;
1648 if (ev.fType == kClientMessage) {
1649 ev.fHandle = xev.xclient.message_type;
1650 ev.fFormat = xev.xclient.format;
1651 ev.fUser[0] = xev.xclient.data.l[0];
1652 if (
sizeof(ev.fUser[0]) > 4) {
1653 AsmLong(xev.xclient.data.l[1], xev.xclient.data.l[3], ev.fUser[1]);
1654 AsmLong(xev.xclient.data.l[2], xev.xclient.data.l[4], ev.fUser[2]);
1656 ev.fUser[1] = xev.xclient.data.l[1];
1657 ev.fUser[2] = xev.xclient.data.l[2];
1658 ev.fUser[3] = xev.xclient.data.l[3];
1659 ev.fUser[4] = xev.xclient.data.l[4];
1662 if (ev.fType == kSelectionClear) {
1663 ev.fUser[0] = xev.xselectionclear.selection;
1665 if (ev.fType == kSelectionRequest) {
1666 ev.fTime = (Time_t) xev.xselectionrequest.time;
1667 ev.fUser[0] = xev.xselectionrequest.requestor;
1668 ev.fUser[1] = xev.xselectionrequest.selection;
1669 ev.fUser[2] = xev.xselectionrequest.target;
1670 ev.fUser[3] = xev.xselectionrequest.property;
1672 if (ev.fType == kSelectionNotify) {
1673 ev.fTime = (Time_t) xev.xselection.time;
1674 ev.fUser[0] = xev.xselection.requestor;
1675 ev.fUser[1] = xev.xselection.selection;
1676 ev.fUser[2] = xev.xselection.target;
1677 ev.fUser[3] = xev.xselection.property;
1679 if (ev.fType == kColormapNotify) {
1680 ev.fHandle = xev.xcolormap.colormap;
1681 ev.fCode = xev.xcolormap.state;
1682 ev.fState = xev.xcolormap.c_new;
1690 void TGX11::Bell(Int_t percent)
1692 XBell((Display*)fDisplay, percent);
1700 void TGX11::CopyArea(Drawable_t src, Drawable_t dest, GContext_t gc,
1701 Int_t src_x, Int_t src_y, UInt_t width, UInt_t height,
1702 Int_t dest_x, Int_t dest_y)
1704 if (!src || !dest)
return;
1706 XCopyArea((Display*)fDisplay, src, dest, (GC) gc, src_x, src_y, width, height,
1713 void TGX11::ChangeWindowAttributes(Window_t
id, SetWindowAttributes_t *attr)
1717 RXSetWindowAttributes xattr;
1721 MapSetWindowAttributes(attr, xmask, xattr);
1723 XChangeWindowAttributes((Display*)fDisplay, (Window)
id, xmask, &xattr);
1725 if (attr && (attr->fMask & kWABorderWidth))
1726 XSetWindowBorderWidth((Display*)fDisplay, (Window)
id, attr->fBorderWidth);
1734 void TGX11::ChangeProperty(Window_t
id, Atom_t property, Atom_t type,
1735 UChar_t *data, Int_t len)
1739 XChangeProperty((Display*)fDisplay, (Window)
id, (Atom) property, (Atom) type,
1740 8, PropModeReplace, data, len);
1746 void TGX11::DrawLine(Drawable_t
id, GContext_t gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
1750 XDrawLine((Display*)fDisplay, (Drawable)
id, (GC) gc, x1, y1, x2, y2);
1756 void TGX11::ClearArea(Window_t
id, Int_t x, Int_t y, UInt_t w, UInt_t h)
1760 XClearArea((Display*)fDisplay, (Window)
id, x, y, w, h, False);
1768 Bool_t TGX11::CheckEvent(Window_t
id, EGEventType type, Event_t &ev)
1770 if (!
id)
return kFALSE;
1778 tev.fUser[0] = tev.fUser[1] = tev.fUser[2] = tev.fUser[3] = tev.fUser[4] = 0;
1784 tev.fX = tev.fY = 0;
1785 tev.fXRoot = tev.fYRoot = 0;
1787 MapEvent(tev, &xev);
1789 Bool r = XCheckTypedWindowEvent((Display*)fDisplay, (Window)
id, xev.type, &xev);
1791 if (r) MapEvent(ev, &xev, kFALSE);
1793 return r ? kTRUE : kFALSE;
1799 void TGX11::SendEvent(Window_t
id, Event_t *ev)
1801 if (!ev || !
id)
return;
1805 MapEvent(*ev, &xev);
1807 XSendEvent((Display*)fDisplay, (Window)
id, False, None, &xev);
1813 void TGX11::WMDeleteNotify(Window_t
id)
1817 XSetWMProtocols((Display*)fDisplay, (Window)
id, &gWM_DELETE_WINDOW, 1);
1823 void TGX11::SetKeyAutoRepeat(Bool_t on)
1826 XAutoRepeatOn((Display*)fDisplay);
1828 XAutoRepeatOff((Display*)fDisplay);
1837 void TGX11::GrabKey(Window_t
id, Int_t keycode, UInt_t modifier, Bool_t grab)
1843 MapModifierState(modifier, xmod);
1846 XGrabKey((Display*)fDisplay, keycode, xmod, (Window)
id, True,
1847 GrabModeAsync, GrabModeAsync);
1849 XUngrabKey((Display*)fDisplay, keycode, xmod, (Window)
id);
1858 void TGX11::GrabButton(Window_t
id, EMouseButton button, UInt_t modifier,
1859 UInt_t evmask, Window_t confine, Cursor_t cursor,
1866 MapModifierState(modifier, xmod);
1870 MapEventMask(evmask, xevmask);
1872 XGrabButton((Display*)fDisplay, button, xmod, (Window)
id, True, xevmask,
1873 GrabModeAsync, GrabModeAsync, (Window) confine,
1876 XUngrabButton((Display*)fDisplay, button, xmod, (Window)
id);
1884 void TGX11::GrabPointer(Window_t
id, UInt_t evmask, Window_t confine,
1885 Cursor_t cursor, Bool_t grab, Bool_t owner_events)
1891 MapEventMask(evmask, xevmask);
1893 XGrabPointer((Display*)fDisplay, (Window)
id, (Bool) owner_events,
1894 xevmask, GrabModeAsync, GrabModeAsync, (Window) confine,
1895 (Cursor) cursor, CurrentTime);
1897 XUngrabPointer((Display*)fDisplay, CurrentTime);
1903 void TGX11::SetWindowName(Window_t
id,
char *name)
1907 XTextProperty wname;
1909 if (XStringListToTextProperty(&name, 1, &wname) == 0) {
1910 Error(
"SetWindowName",
"cannot allocate window name \"%s\"", name);
1913 XSetWMName((Display*)fDisplay, (Window)
id, &wname);
1920 void TGX11::SetIconName(Window_t
id,
char *name)
1924 XTextProperty wname;
1926 if (XStringListToTextProperty(&name, 1, &wname) == 0) {
1927 Error(
"SetIconName",
"cannot allocate icon name \"%s\"", name);
1930 XSetWMIconName((Display*)fDisplay, (Window)
id, &wname);
1937 void TGX11::SetIconPixmap(Window_t
id, Pixmap_t pic)
1943 hints.flags = IconPixmapHint;
1944 hints.icon_pixmap = (Pixmap) pic;
1946 XSetWMHints((Display*)fDisplay, (Window)
id, &hints);
1952 void TGX11::SetClassHints(Window_t
id,
char *className,
char *resourceName)
1956 XClassHint class_hints;
1958 class_hints.res_class = className;
1959 class_hints.res_name = resourceName;
1960 XSetClassHint((Display*)fDisplay, (Window)
id, &class_hints);
1966 void TGX11::SetMWMHints(Window_t
id, UInt_t value, UInt_t funcs, UInt_t input)
1970 MWMHintsProperty_t prop;
1972 prop.fDecorations = value;
1973 prop.fFunctions = funcs;
1974 prop.fInputMode = input;
1975 prop.fFlags = kMWMHintsDecorations | kMWMHintsFunctions | kMWMHintsInputMode;
1977 XChangeProperty((Display*)fDisplay, (Window)
id, gMOTIF_WM_HINTS, gMOTIF_WM_HINTS, 32,
1978 PropModeReplace, (UChar_t *)&prop, kPropMWMHintElements);
1984 void TGX11::SetWMPosition(Window_t
id, Int_t x, Int_t y)
1990 hints.flags = USPosition | PPosition;
1994 XSetWMNormalHints((Display*)fDisplay, (Window)
id, &hints);
2000 void TGX11::SetWMSize(Window_t
id, UInt_t w, UInt_t h)
2006 hints.flags = USSize | PSize | PBaseSize;
2007 hints.width = hints.base_width = w;
2008 hints.height = hints.base_height = h;
2010 XSetWMNormalHints((Display*)fDisplay, (Window)
id, &hints);
2017 void TGX11::SetWMSizeHints(Window_t
id, UInt_t wmin, UInt_t hmin,
2018 UInt_t wmax, UInt_t hmax,
2019 UInt_t winc, UInt_t hinc)
2025 hints.flags = PMinSize | PMaxSize | PResizeInc;
2026 hints.min_width = (Int_t)wmin;
2027 hints.max_width = (Int_t)wmax;
2028 hints.min_height = (Int_t)hmin;
2029 hints.max_height = (Int_t)hmax;
2030 hints.width_inc = (Int_t)winc;
2031 hints.height_inc = (Int_t)hinc;
2033 XSetWMNormalHints((Display*)fDisplay, (Window)
id, &hints);
2039 void TGX11::SetWMState(Window_t
id, EInitialState state)
2044 Int_t xstate = NormalState;
2046 if (state == kNormalState)
2047 xstate = NormalState;
2048 if (state == kIconicState)
2049 xstate = IconicState;
2051 hints.flags = StateHint;
2052 hints.initial_state = xstate;
2054 XSetWMHints((Display*)fDisplay, (Window)
id, &hints);
2060 void TGX11::SetWMTransientHint(Window_t
id, Window_t main_id)
2064 XSetTransientForHint((Display*)fDisplay, (Window)
id, (Window) main_id);
2070 void TGX11::DrawString(Drawable_t
id, GContext_t gc, Int_t x, Int_t y,
2071 const char *s, Int_t len)
2075 XDrawString((Display*)fDisplay, (Drawable)
id, (GC) gc, x, y, (
char *) s, len);
2081 Int_t TGX11::TextWidth(FontStruct_t font,
const char *s, Int_t len)
2083 return XTextWidth((XFontStruct*) font, (
char*) s, len);
2089 void TGX11::GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent)
2091 XFontStruct *f = (XFontStruct *) font;
2093 max_ascent = f->max_bounds.ascent;
2094 max_descent = f->max_bounds.descent;
2102 void TGX11::GetGCValues(GContext_t gc, GCValues_t &gval)
2109 gval.fMask = kMaxUInt;
2112 MapGCValues(gval, xmask, xgval);
2114 XGetGCValues((Display*)fDisplay, (GC) gc, xmask, &xgval);
2116 MapGCValues(gval, xmask, xgval, kFALSE);
2123 FontStruct_t TGX11::GetFontStruct(FontH_t fh)
2127 fs = XQueryFont((Display*)fDisplay, (Font) fh);
2129 return (FontStruct_t) fs;
2135 void TGX11::FreeFontStruct(FontStruct_t fs)
2138 static int xfree86_400 = -1;
2139 if (xfree86_400 == -1) {
2140 if (strstr(XServerVendor((Display*)fDisplay),
"XFree86") &&
2141 XVendorRelease((Display*)fDisplay) == 4000)
2147 if (xfree86_400 == 0)
2148 XFreeFontInfo(0, (XFontStruct *) fs, 1);
2154 void TGX11::ClearWindow(Window_t
id)
2158 XClearWindow((Display*)fDisplay, (Window)
id);
2166 Int_t TGX11::KeysymToKeycode(UInt_t keysym)
2169 MapKeySym(keysym, xkeysym);
2171 return XKeysymToKeycode((Display*)fDisplay, xkeysym);
2177 void TGX11::FillRectangle(Drawable_t
id, GContext_t gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
2181 XFillRectangle((Display*)fDisplay, (Drawable)
id, (GC) gc, x, y, w, h);
2187 void TGX11::DrawRectangle(Drawable_t
id, GContext_t gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
2191 XDrawRectangle((Display*)fDisplay, (Drawable)
id, (GC) gc, x, y, w, h);
2197 void TGX11::DrawSegments(Drawable_t
id, GContext_t gc, Segment_t *seg, Int_t nseg)
2201 XDrawSegments((Display*)fDisplay, (Drawable)
id, (GC) gc, (XSegment *) seg, nseg);
2210 void TGX11::SelectInput(Window_t
id, UInt_t evmask)
2216 MapEventMask(evmask, xevmask);
2218 XSelectInput((Display*)fDisplay, (Window)
id, xevmask);
2224 Window_t TGX11::GetInputFocus()
2229 XGetInputFocus((Display*)fDisplay, &focus, &return_to);
2230 return (Window_t) focus;
2236 void TGX11::SetInputFocus(Window_t
id)
2240 XWindowAttributes xattr;
2242 XGetWindowAttributes((Display*)fDisplay, (Window)
id, &xattr);
2244 if (xattr.map_state == IsViewable)
2245 XSetInputFocus((Display*)fDisplay, (Window)
id, RevertToParent, CurrentTime);
2252 Window_t TGX11::GetPrimarySelectionOwner()
2254 return (Window_t) XGetSelectionOwner((Display*)fDisplay, XA_PRIMARY);
2261 void TGX11::SetPrimarySelectionOwner(Window_t
id)
2265 XSetSelectionOwner((Display*)fDisplay, XA_PRIMARY,
id, CurrentTime);
2279 void TGX11::ConvertPrimarySelection(Window_t
id, Atom_t clipboard, Time_t when)
2283 XConvertSelection((Display*)fDisplay, XA_PRIMARY, XA_STRING, (Atom) clipboard,
2284 (Window)
id, (Time) when);
2293 void TGX11::LookupString(Event_t *event,
char *buf, Int_t buflen, UInt_t &keysym)
2298 MapEvent(*event, &xev);
2300 int n = XLookupString(&xev.xkey, buf, buflen-1, &xkeysym, 0);
2302 Error(
"LookupString",
"buf too small, must be at least %d", n+1);
2306 UInt_t ks, xks = (UInt_t) xkeysym;
2307 MapKeySym(ks, xks, kFALSE);
2308 keysym = (Int_t) ks;
2315 void TGX11::MapKeySym(UInt_t &keysym, UInt_t &xkeysym, Bool_t tox)
2318 xkeysym = XK_VoidSymbol;
2321 }
else if (keysym >= kKey_F1 && keysym <= kKey_F35) {
2322 xkeysym = XK_F1 + (keysym - (UInt_t)kKey_F1);
2324 for (
int i = 0; gKeyMap[i].fKeySym; i++) {
2325 if (keysym == (UInt_t) gKeyMap[i].fKeySym) {
2326 xkeysym = (UInt_t) gKeyMap[i].fXKeySym;
2332 keysym = kKey_Unknown;
2334 if (xkeysym < 127) {
2336 }
else if (xkeysym >= XK_F1 && xkeysym <= XK_F35) {
2337 keysym = kKey_F1 + (xkeysym - XK_F1);
2338 }
else if (xkeysym >= XK_KP_0 && xkeysym <= XK_KP_9) {
2339 keysym = kKey_0 + (xkeysym - XK_KP_0);
2341 for (
int i = 0; gKeyMap[i].fXKeySym; i++) {
2342 if (xkeysym == gKeyMap[i].fXKeySym) {
2343 keysym = (UInt_t) gKeyMap[i].fKeySym;
2355 void TGX11::GetPasteBuffer(Window_t
id, Atom_t atom, TString &text, Int_t &nchar,
2360 Atom actual_type,
property = (Atom) atom;
2362 ULong_t nitems, bytes_after, nread;
2363 unsigned char *data;
2368 if (property == None)
return;
2373 if (XGetWindowProperty((Display*)fDisplay, (Window)
id, property,
2374 nread/4, 1024, (Bool)del,
2376 &actual_type, &actual_format,
2377 &nitems, &bytes_after,
2378 (
unsigned char **) &data)
2382 if (actual_type != XA_STRING)
break;
2384 text.Insert((Int_t) nread, (
const char *) data, (Int_t) nitems);
2388 }
while (bytes_after > 0);
2390 nchar = (Int_t) nread;
2399 void TGX11::TranslateCoordinates(Window_t src, Window_t dest, Int_t src_x,
2400 Int_t src_y, Int_t &dest_x, Int_t &dest_y, Window_t &child)
2402 if (!src || !dest)
return;
2406 XTranslateCoordinates((Display*)fDisplay, (Window) src, (Window) dest, src_x,
2407 src_y, &dest_x, &dest_y, &xchild);
2408 child = (Window_t) xchild;
2415 void TGX11::GetWindowSize(Drawable_t
id, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h)
2422 XGetGeometry((Display*)fDisplay, (Drawable)
id, &wdummy, &x, &y, &w, &h, &bdum, &ddum);
2433 void TGX11::FillPolygon(Window_t
id, GContext_t gc, Point_t *points, Int_t npnt)
2437 XFillPolygon((Display*)fDisplay, (Window)
id, (GC) gc, (XPoint *) points, npnt,
2438 Convex, CoordModeOrigin);
2450 void TGX11::QueryPointer(Window_t
id, Window_t &rootw, Window_t &childw,
2451 Int_t &root_x, Int_t &root_y, Int_t &win_x,
2452 Int_t &win_y, UInt_t &mask)
2456 Window xrootw, xchildw;
2459 XQueryPointer((Display*)fDisplay, (Window)
id, &xrootw, &xchildw,
2460 &root_x, &root_y, &win_x, &win_y, &xmask);
2462 rootw = (Window_t) xrootw;
2463 childw = (Window_t) xchildw;
2465 MapModifierState(mask, xmask, kFALSE);
2472 void TGX11::SetForeground(GContext_t gc, ULong_t foreground)
2474 XSetForeground((Display*)fDisplay, (GC) gc, foreground);
2482 void TGX11::SetClipRectangles(GContext_t gc, Int_t x, Int_t y, Rectangle_t *recs, Int_t n)
2484 XSetClipRectangles((Display*)fDisplay, (GC) gc, x, y, (XRectangle *) recs, n, Unsorted);
2492 void TGX11::Update(Int_t mode)
2495 XFlush((Display*)fDisplay);
2497 XSync((Display*)fDisplay, False);
2503 Region_t TGX11::CreateRegion()
2505 return (Region_t) XCreateRegion();
2511 void TGX11::DestroyRegion(Region_t reg)
2513 XDestroyRegion((Region)reg);
2519 void TGX11::UnionRectWithRegion(Rectangle_t *rect, Region_t src, Region_t dest)
2521 XRectangle *r = (XRectangle *) rect;
2522 XUnionRectWithRegion(r, (Region) src, (Region) dest);
2529 Region_t TGX11::PolygonRegion(Point_t *points, Int_t np, Bool_t winding)
2531 XPoint *p = (XPoint *) points;
2532 return (Region_t) XPolygonRegion(p, np, winding ? WindingRule : EvenOddRule);
2539 void TGX11::UnionRegion(Region_t rega, Region_t regb, Region_t result)
2541 XUnionRegion((Region) rega, (Region) regb, (Region) result);
2548 void TGX11::IntersectRegion(Region_t rega, Region_t regb, Region_t result)
2550 XIntersectRegion((Region) rega, (Region) regb, (Region) result);
2556 void TGX11::SubtractRegion(Region_t rega, Region_t regb, Region_t result)
2558 XSubtractRegion((Region) rega, (Region) regb, (Region) result);
2565 void TGX11::XorRegion(Region_t rega, Region_t regb, Region_t result)
2567 XXorRegion((Region) rega, (Region) regb, (Region) result);
2573 Bool_t TGX11::EmptyRegion(Region_t reg)
2575 return (Bool_t) XEmptyRegion((Region) reg);
2581 Bool_t TGX11::PointInRegion(Int_t x, Int_t y, Region_t reg)
2583 return (Bool_t) XPointInRegion((Region) reg, x, y);
2589 Bool_t TGX11::EqualRegion(Region_t rega, Region_t regb)
2591 return (Bool_t) XEqualRegion((Region) rega, (Region) regb);
2597 void TGX11::GetRegionBox(Region_t reg, Rectangle_t *rect)
2599 XClipBox((Region) reg, (XRectangle*) rect);
2605 char **TGX11::ListFonts(
const char *fontname, Int_t max, Int_t &count)
2608 Int_t fontcount = 0;
2609 fontlist = XListFonts((Display*)fDisplay, (
char *)fontname, max, &fontcount);
2617 void TGX11::FreeFontNames(
char **fontlist)
2619 XFreeFontNames(fontlist);
2625 Drawable_t TGX11::CreateImage(UInt_t width, UInt_t height)
2631 else if (fDepth <= 16)
2636 XImage *xim = XCreateImage((Display*)fDisplay, fVisual, fDepth, ZPixmap,
2637 0, 0, width, height, bitmap_pad, 0);
2640 if (xim) xim->data = (
char *) calloc(xim->bytes_per_line * xim->height, 1);
2642 return (Drawable_t) xim;
2648 void TGX11::GetImageSize(Drawable_t img, UInt_t &width, UInt_t &height)
2650 width = ((XImage*)img)->width;
2651 height = ((XImage*)img)->height;
2657 void TGX11::PutPixel(Drawable_t img, Int_t x, Int_t y, ULong_t pixel)
2659 XPutPixel((XImage*) img, x, y, pixel);
2665 void TGX11::PutImage(Drawable_t win, GContext_t gc, Drawable_t img, Int_t dx,
2666 Int_t dy, Int_t x, Int_t y, UInt_t w, UInt_t h)
2670 XPutImage((Display*)fDisplay, (Drawable) win, (GC) gc, (XImage*) img,
2671 x, y, dx, dy, w, h);
2677 void TGX11::DeleteImage(Drawable_t img)
2679 XDestroyImage((XImage*) img);
2687 void TGX11::ShapeCombineMask(Window_t
id, Int_t x, Int_t y, Pixmap_t mask)
2689 XShapeCombineMask((Display*)fDisplay, (Window)
id, ShapeBounding, x, y,
2690 (Pixmap) mask, ShapeSet);
2696 UInt_t TGX11::ScreenWidthMM()
const
2698 return (UInt_t)WidthMMOfScreen(DefaultScreenOfDisplay((Display*)fDisplay));
2706 void TGX11::DeleteProperty(Window_t win, Atom_t& prop)
2708 XDeleteProperty((Display*)fDisplay, win, prop);
2717 Int_t TGX11::GetProperty(Window_t win, Atom_t prop, Long_t offset, Long_t length,
2718 Bool_t del, Atom_t req_type, Atom_t *act_type,
2719 Int_t *act_format, ULong_t *nitems, ULong_t *bytes,
2720 unsigned char **prop_list)
2722 return XGetWindowProperty((Display*)fDisplay, win, prop, offset, length, del, req_type,
2723 act_type, act_format, nitems, bytes, prop_list);
2730 void TGX11::ChangeActivePointerGrab(Window_t , UInt_t mask, Cursor_t cur)
2733 MapEventMask(mask, xevmask);
2735 XChangeActivePointerGrab((Display*)fDisplay, xevmask, fCursors[kHand], CurrentTime);
2737 XChangeActivePointerGrab((Display*)fDisplay, xevmask, cur, CurrentTime);
2744 void TGX11::ConvertSelection(Window_t win, Atom_t &sel, Atom_t &target,
2745 Atom_t &prop, Time_t &stamp)
2747 XConvertSelection((Display*)fDisplay, sel, target, prop, win, stamp);
2753 Bool_t TGX11::SetSelectionOwner(Window_t owner, Atom_t &sel)
2755 return XSetSelectionOwner((Display*)fDisplay, sel, owner, CurrentTime);
2763 void TGX11::ChangeProperties(Window_t
id, Atom_t property, Atom_t type,
2764 Int_t format, UChar_t *data, Int_t len)
2768 XChangeProperty((Display*)fDisplay, (Window)
id, (Atom) property, (Atom) type,
2769 format, PropModeReplace, data, len);
2776 void TGX11::SetDNDAware(Window_t win, Atom_t *typelist)
2778 unsigned char version = 4;
2779 Atom_t dndaware = InternAtom(
"XdndAware", kFALSE);
2780 XChangeProperty((Display*)fDisplay, (Window) win, (Atom) dndaware, (Atom) XA_ATOM,
2781 32, PropModeReplace, (
unsigned char *) &version, 1);
2786 for (n = 0; typelist[n]; n++) { }
2788 XChangeProperty((Display*)fDisplay, win, dndaware, XA_ATOM, 32, PropModeAppend,
2789 (
unsigned char *) typelist, n);
2797 void TGX11::SetTypeList(Window_t win, Atom_t prop, Atom_t *typelist)
2801 for (n = 0; typelist[n]; n++) { }
2803 XChangeProperty((Display*)fDisplay, win, prop, XA_ATOM, 32, PropModeAppend,
2804 (
unsigned char *) typelist, n);
2814 Window_t TGX11::FindRWindow(Window_t win, Window_t dragwin, Window_t input,
2815 int x,
int y,
int maxd)
2817 WindowAttributes_t wattr;
2818 static Atom_t *dndTypeList = 0;
2820 if (dndTypeList == 0) {
2821 dndTypeList =
new Atom_t[3];
2822 dndTypeList[0] = InternAtom(
"application/root", kFALSE);
2823 dndTypeList[1] = InternAtom(
"text/uri-list", kFALSE);
2827 if (maxd <= 0)
return kNone;
2829 if (win == dragwin || win == input)
return kNone;
2831 GetWindowAttributes(win, wattr);
2832 if (wattr.fMapState != kIsUnmapped &&
2833 x >= wattr.fX && x < wattr.fX + wattr.fWidth &&
2834 y >= wattr.fY && y < wattr.fY + wattr.fHeight) {
2836 if (IsDNDAware(win, dndTypeList))
return win;
2838 Window r, p, *children;
2842 if (XQueryTree((Display*)fDisplay, win, &r, &p, &children, &numch)) {
2843 if (children && numch > 0) {
2847 for (i = numch-1; i >= 0; --i) {
2848 r = FindRWindow((Window_t)children[i], dragwin, input,
2849 x - wattr.fX, y - wattr.fY, maxd-1);
2850 if (r != kNone)
break;
2853 if (r != kNone)
return r;
2865 Bool_t TGX11::IsDNDAware(Window_t win, Atom_t *typelist)
2869 ULong_t count, remaining;
2870 unsigned char *data = 0;
2872 Int_t result = kTRUE;
2873 static Atom_t dndaware = kNone;
2875 if (win == kNone)
return kFALSE;
2877 if (dndaware == kNone)
2878 dndaware = InternAtom(
"XdndAware", kFALSE);
2880 XGetWindowProperty((Display*)fDisplay, win, dndaware, 0, 0x8000000L, kFALSE,
2881 XA_ATOM, &actual, &format, &count, &remaining, &data);
2883 if ((actual != XA_ATOM) || (format != 32) || (count == 0) || !data) {
2884 if (data) XFree(data);
2888 types = (Atom_t *) data;
2890 if ((count > 1) && typelist) {
2892 for (t = typelist; *t; t++) {
2893 for (ULong_t j = 1; j < count; j++) {
2894 if (types[j] == *t) {