ROOT  6.06/09
Reference Guide
GX11Gui.cxx
Go to the documentation of this file.
1 // @(#)root/x11:$Id$
2 // Author: Fons Rademakers 28/12/97
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TGX11
13 */
14 
15 // This file contains the implementation of the GUI methods of the
16 // TGX11 class. Most of the methods are used by the machine independent
17 // GUI classes (libGUI.so).
18 
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
22 #include <ctype.h>
23 #include <limits.h>
24 #include <unistd.h>
25 
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
29 #include <X11/cursorfont.h>
30 #include <X11/keysym.h>
31 #include <X11/xpm.h>
32 
33 #include "TGX11.h"
34 #include "TROOT.h"
35 #include "TError.h"
36 #include "TSystem.h"
37 #include "TException.h"
38 #include "TClassTable.h"
39 #include "KeySymbols.h"
40 #include "TEnv.h"
41 
42 #include <X11/extensions/shape.h>
43 
44 //---- MWM Hints stuff
45 
46 struct MWMHintsProperty_t {
47  Handle_t fFlags;
48  Handle_t fFunctions;
49  Handle_t fDecorations;
50  Int_t fInputMode;
51 };
52 
53 //---- hints
54 
58 
61 
62 
63 //---- Key symbol mapping
64 
65 struct KeySymbolMap_t {
66  KeySym fXKeySym;
67  EKeySym fKeySym;
68 };
69 
70 //---- Mapping table of all non-trivial mappings (the ASCII keys map
71 //---- one to one so are not included)
72 
73 static KeySymbolMap_t gKeyMap[] = {
74  { XK_Escape, kKey_Escape },
75  { XK_Tab, kKey_Tab },
76 #ifndef XK_ISO_Left_Tab
77  { 0xFE20, kKey_Backtab },
78 #else
79  { XK_ISO_Left_Tab, kKey_Backtab },
80 #endif
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 }, // hardcoded Sun SysReq
89  { 0x1007ff00, kKey_SysReq }, // hardcoded X386 SysReq
90  { XK_Home, kKey_Home }, // cursor movement
91  { XK_End, kKey_End },
92  { XK_Left, kKey_Left },
93  { XK_Up, kKey_Up },
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 }, // modifiers
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 }, // numeric keypad
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 },
137  { 0, (EKeySym) 0 }
138 };
139 
140 struct RXGCValues:XGCValues{};
141 struct RXColor:XColor{};
142 struct RXpmAttributes:XpmAttributes{};
143 struct RXSetWindowAttributes:XSetWindowAttributes{};
144 struct RVisual:Visual{};
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 
148 inline void SplitLong(Long_t ll, Long_t &i1, Long_t &i2)
149 {
150  union { Long_t l; Int_t i[2]; } conv;
151 
152  conv.l = ll;
153  i1 = conv.i[0];
154  i2 = conv.i[1];
155 }
156 
157 ////////////////////////////////////////////////////////////////////////////////
158 
159 inline void AsmLong(Long_t i1, Long_t i2, Long_t &ll)
160 {
161  union { Long_t l; Int_t i[2]; } conv;
162 
163  conv.i[0] = (Int_t) i1;
164  conv.i[1] = (Int_t) i2;
165  ll = conv.l;
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Handle X11 error.
170 
171 static Int_t RootX11ErrorHandler(Display *disp, XErrorEvent *err)
172 {
173  char msg[80];
174  XGetErrorText(disp, err->error_code, msg, 80);
175 
176  // force segV. to allow backtracing the error with gdb
177  if (gDebug == (Long_t)gVirtualX) {
179  ::Error("RootX11ErrorHandler", "%s (XID: %u, XREQ: %u)", msg,
180  (UInt_t)err->resourceid, err->request_code);
181  int *kil = (int*)1;
182  delete kil;
183  return 0;
184  }
185 
186  if (!err->resourceid) return 0;
187 
188  TObject *w = (TObject *)gROOT->ProcessLineFast(Form("gClient->GetWindowById(%lu)", (ULong_t)err->resourceid));
189 
190  if (!w) {
191  ::Error("RootX11ErrorHandler", "%s (XID: %u, XREQ: %u)", msg,
192  (UInt_t)err->resourceid, err->request_code);
193  } else {
194  ::Error("RootX11ErrorHandler", "%s (%s XID: %u, XREQ: %u)", msg, w->ClassName(),
195  (UInt_t)err->resourceid, err->request_code);
196  w->Print("tree");
197  }
198  if (TROOT::Initialized()) {
199  //Getlinem(kInit, "Root > ");
200  Throw(2);
201  }
202  return 0;
203 }
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Handle X11 I/O error (happens when connection to display server
207 /// is broken).
208 
209 static Int_t RootX11IOErrorHandler(Display *)
210 {
211  ::Error("RootX11IOErrorHandler", "fatal X11 error (connection to server lost?!)");
212  fprintf(stderr,"\n**** Save data and exit application ****\n\n");
213  // delete X connection handler (to avoid looping in TSystem::DispatchOneEvent())
214  if (gXDisplay && gSystem) {
217  }
218  if (TROOT::Initialized()) {
219  //Getlinem(kInit, "Root > ");
220  Throw(2);
221  }
222  return 0;
223 }
224 
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Map window on screen.
228 
230 {
231  if (!id) return;
232 
233  XMapWindow((Display*)fDisplay, (Window) id);
234 }
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 /// Map sub windows.
238 
240 {
241  if (!id) return;
242 
243  XMapSubwindows((Display*)fDisplay, (Window) id);
244 }
245 
246 ////////////////////////////////////////////////////////////////////////////////
247 /// Map window on screen and put on top of all windows.
248 
250 {
251  if (!id) return;
252 
253  XMapRaised((Display*)fDisplay, (Window) id);
254 }
255 
256 ////////////////////////////////////////////////////////////////////////////////
257 /// Unmap window from screen.
258 
260 {
261  if (!id) return;
262 
263  XUnmapWindow((Display*)fDisplay, (Window) id);
264 }
265 
266 ////////////////////////////////////////////////////////////////////////////////
267 /// Destroy window.
268 
270 {
271  if (!id) return;
272 
273  XDestroyWindow((Display*)fDisplay, (Window) id);
274 }
275 
276 ////////////////////////////////////////////////////////////////////////////////
277 /// Destroy subwindows of this window.
278 
280 {
281  if (!id) return;
282 
283  XDestroySubwindows((Display*)fDisplay, (Window) id);
284 }
285 
286 ////////////////////////////////////////////////////////////////////////////////
287 /// Put window on top of window stack.
288 
290 {
291  if (!id) return;
292 
293  XRaiseWindow((Display*)fDisplay, (Window) id);
294 }
295 
296 ////////////////////////////////////////////////////////////////////////////////
297 /// Lower window so it lays below all its siblings.
298 
300 {
301  if (!id) return;
302 
303  XLowerWindow((Display*)fDisplay, (Window) id);
304 }
305 
306 ////////////////////////////////////////////////////////////////////////////////
307 /// Move a window.
308 
310 {
311  if (!id) return;
312 
313  XMoveWindow((Display*)fDisplay, (Window) id, x, y);
314 }
315 
316 ////////////////////////////////////////////////////////////////////////////////
317 /// Move and resize a window.
318 
320 {
321  if (!id) return;
322 
323  XMoveResizeWindow((Display*)fDisplay, (Window) id, x, y, w, h);
324 }
325 
326 ////////////////////////////////////////////////////////////////////////////////
327 /// Resize the window.
328 
330 {
331  if (!id) return;
332 
333  // protect against potential negative values
334  if (w >= (UInt_t)INT_MAX || h >= (UInt_t)INT_MAX)
335  return;
336  XResizeWindow((Display*)fDisplay, (Window) id, w, h);
337 }
338 
339 ////////////////////////////////////////////////////////////////////////////////
340 /// Iconify the window.
341 
343 {
344  if (!id) return;
345 
346  XIconifyWindow((Display*)fDisplay, (Window) id, fScreenNumber);
347 }
348 
349 ////////////////////////////////////////////////////////////////////////////////
350 /// Reparent window to new parent window at position (x,y).
351 
353 {
354  if (!id) return;
355 
356  XReparentWindow((Display*)fDisplay, (Window) id, (Window) pid, x, y);
357 }
358 
359 ////////////////////////////////////////////////////////////////////////////////
360 /// Set the window background color.
361 
363 {
364  if (!id) return;
365 
366  XSetWindowBackground((Display*)fDisplay, (Window) id, color);
367 }
368 
369 ////////////////////////////////////////////////////////////////////////////////
370 /// Set pixmap as window background.
371 
373 {
374  if (!id) return;
375 
376  XSetWindowBackgroundPixmap((Display*)fDisplay, (Window) id, (Pixmap) pxm);
377 }
378 
379 ////////////////////////////////////////////////////////////////////////////////
380 /// Return handle to newly created X window.
381 
383  UInt_t w, UInt_t h, UInt_t border,
384  Int_t depth, UInt_t clss,
385  void *visual, SetWindowAttributes_t *attr, UInt_t)
386 {
387  RXSetWindowAttributes xattr;
388  ULong_t xmask = 0;
389 
390  if (attr)
391  MapSetWindowAttributes(attr, xmask, xattr);
392 
393  if (depth == 0)
394  depth = fDepth;
395  if (visual == 0)
396  visual = fVisual;
397  if (fColormap && !(xmask & CWColormap)) {
398  xmask |= CWColormap;
399  xattr.colormap = fColormap;
400  }
401  if ((Window)parent == fRootWin && fRootWin != fVisRootWin) {
402  xmask |= CWBorderPixel;
403  xattr.border_pixel = fBlackPixel;
404  }
405 
406  return (Window_t) XCreateWindow((Display*)fDisplay, (Window) parent, x, y,
407  w, h, border, depth, clss, (Visual*)visual,
408  xmask, &xattr);
409 }
410 
411 ////////////////////////////////////////////////////////////////////////////////
412 /// Map event mask to or from X.
413 
414 void TGX11::MapEventMask(UInt_t &emask, UInt_t &xemask, Bool_t tox)
415 {
416  if (tox) {
417  Long_t lxemask = NoEventMask;
418  if ((emask & kKeyPressMask))
419  lxemask |= KeyPressMask;
420  if ((emask & kKeyReleaseMask))
421  lxemask |= KeyReleaseMask;
422  if ((emask & kButtonPressMask))
423  lxemask |= ButtonPressMask;
424  if ((emask & kButtonReleaseMask))
425  lxemask |= ButtonReleaseMask;
426  if ((emask & kPointerMotionMask))
427  lxemask |= PointerMotionMask;
428  if ((emask & kButtonMotionMask))
429  lxemask |= ButtonMotionMask;
430  if ((emask & kExposureMask))
431  lxemask |= ExposureMask;
432  if ((emask & kStructureNotifyMask))
433  lxemask |= StructureNotifyMask;
434  if ((emask & kEnterWindowMask))
435  lxemask |= EnterWindowMask;
436  if ((emask & kLeaveWindowMask))
437  lxemask |= LeaveWindowMask;
438  if ((emask & kFocusChangeMask))
439  lxemask |= FocusChangeMask;
440  if ((emask & kOwnerGrabButtonMask))
441  lxemask |= OwnerGrabButtonMask;
442  if ((emask & kColormapChangeMask))
443  lxemask |= ColormapChangeMask;
444  xemask = (UInt_t)lxemask;
445  } else {
446  emask = 0;
447  if ((xemask & KeyPressMask))
448  emask |= kKeyPressMask;
449  if ((xemask & KeyReleaseMask))
450  emask |= kKeyReleaseMask;
451  if ((xemask & ButtonPressMask))
452  emask |= kButtonPressMask;
453  if ((xemask & ButtonReleaseMask))
454  emask |= kButtonReleaseMask;
455  if ((xemask & PointerMotionMask))
456  emask |= kPointerMotionMask;
457  if ((xemask & ButtonMotionMask))
458  emask |= kButtonMotionMask;
459  if ((xemask & ExposureMask))
460  emask |= kExposureMask;
461  if ((xemask & StructureNotifyMask))
462  emask |= kStructureNotifyMask;
463  if ((xemask & EnterWindowMask))
464  emask |= kEnterWindowMask;
465  if ((xemask & LeaveWindowMask))
466  emask |= kLeaveWindowMask;
467  if ((xemask & FocusChangeMask))
468  emask |= kFocusChangeMask;
469  if ((xemask & OwnerGrabButtonMask))
470  emask |= kOwnerGrabButtonMask;
471  if ((xemask & ColormapChangeMask))
472  emask |= kColormapChangeMask;
473  }
474 }
475 
476 ////////////////////////////////////////////////////////////////////////////////
477 /// Map a SetWindowAttributes_t to a XSetWindowAttributes structure.
478 
480  ULong_t &xmask, RXSetWindowAttributes &xattr)
481 {
482  Mask_t mask = attr->fMask;
483  xmask = 0;
484 
485  if ((mask & kWABackPixmap)) {
486  xmask |= CWBackPixmap;
487  if (attr->fBackgroundPixmap == kNone)
488  xattr.background_pixmap = None;
489  else if (attr->fBackgroundPixmap == kParentRelative)
490  xattr.background_pixmap = ParentRelative;
491  else
492  xattr.background_pixmap = (Pixmap)attr->fBackgroundPixmap;
493  }
494  if ((mask & kWABackPixel)) {
495  xmask |= CWBackPixel;
496  xattr.background_pixel = attr->fBackgroundPixel;
497  }
498  if ((mask & kWABorderPixmap)) {
499  xmask |= CWBorderPixmap;
500  xattr.border_pixmap = (Pixmap)attr->fBorderPixmap;
501  }
502  if ((mask & kWABorderPixel)) {
503  xmask |= CWBorderPixel;
504  xattr.border_pixel = attr->fBorderPixel;
505  }
506  if ((mask & kWABitGravity)) {
507  xmask |= CWBitGravity;
508  xattr.bit_gravity = attr->fBitGravity; //assume ident mapping (rdm)
509  }
510  if ((mask & kWAWinGravity)) {
511  xmask |= CWWinGravity;
512  xattr.win_gravity = attr->fWinGravity; // assume ident mapping (rdm)
513  }
514  if ((mask & kWABackingStore)) {
515  xmask |= CWBackingStore;
516  if (attr->fBackingStore == kNotUseful)
517  xattr.backing_store = NotUseful;
518  else if (attr->fBackingStore == kWhenMapped)
519  xattr.backing_store = WhenMapped;
520  else if (attr->fBackingStore == kAlways)
521  xattr.backing_store = Always;
522  else
523  xattr.backing_store = attr->fBackingStore;
524  }
525  if ((mask & kWABackingPlanes)) {
526  xmask |= CWBackingPlanes;
527  xattr.backing_planes = attr->fBackingPlanes;
528  }
529  if ((mask & kWABackingPixel)) {
530  xmask |= CWBackingPixel;
531  xattr.backing_pixel = attr->fBackingPixel;
532  }
533  if ((mask & kWAOverrideRedirect)) {
534  xmask |= CWOverrideRedirect;
535  xattr.override_redirect = attr->fOverrideRedirect;
536  }
537  if ((mask & kWASaveUnder)) {
538  xmask |= CWSaveUnder;
539  xattr.save_under = (Bool)attr->fSaveUnder;
540  }
541  if ((mask & kWAEventMask)) {
542  xmask |= CWEventMask;
543  UInt_t xmsk, msk = (UInt_t) attr->fEventMask;
544  MapEventMask(msk, xmsk, kTRUE);
545  xattr.event_mask = xmsk;
546  }
547  if ((mask & kWADontPropagate)) {
548  xmask |= CWDontPropagate;
549  xattr.do_not_propagate_mask = attr->fDoNotPropagateMask;
550  }
551  if ((mask & kWAColormap)) {
552  xmask |= CWColormap;
553  xattr.colormap = (Colormap)attr->fColormap;
554  }
555  if ((mask & kWACursor)) {
556  xmask |= CWCursor;
557  if (attr->fCursor == kNone)
558  xattr.cursor = None;
559  else
560  xattr.cursor = (Cursor)attr->fCursor;
561  }
562 }
563 
564 ////////////////////////////////////////////////////////////////////////////////
565 /// Map a GCValues_t to a XCGValues structure if tox is true. Map
566 /// the other way in case tox is false.
567 
569  ULong_t &xmask, RXGCValues &xgval, Bool_t tox)
570 {
571  if (tox) {
572  // map GCValues_t to XGCValues
573  Mask_t mask = gval.fMask;
574  xmask = 0;
575 
576  if ((mask & kGCFunction)) {
577  xmask |= GCFunction;
578  xgval.function = gval.fFunction; // ident mapping
579  }
580  if ((mask & kGCPlaneMask)) {
581  xmask |= GCPlaneMask;
582  xgval.plane_mask = gval.fPlaneMask;
583  }
584  if ((mask & kGCForeground)) {
585  xmask |= GCForeground;
586  xgval.foreground = gval.fForeground;
587  }
588  if ((mask & kGCBackground)) {
589  xmask |= GCBackground;
590  xgval.background = gval.fBackground;
591  }
592  if ((mask & kGCLineWidth)) {
593  xmask |= GCLineWidth;
594  xgval.line_width = gval.fLineWidth;
595  }
596  if ((mask & kGCLineStyle)) {
597  xmask |= GCLineStyle;
598  xgval.line_style = gval.fLineStyle; // ident mapping
599  }
600  if ((mask & kGCCapStyle)) {
601  xmask |= GCCapStyle;
602  xgval.cap_style = gval.fCapStyle; // ident mapping
603  }
604  if ((mask & kGCJoinStyle)) {
605  xmask |= GCJoinStyle;
606  xgval.join_style = gval.fJoinStyle; // ident mapping
607  }
608  if ((mask & kGCFillStyle)) {
609  xmask |= GCFillStyle;
610  xgval.fill_style = gval.fFillStyle; // ident mapping
611  }
612  if ((mask & kGCFillRule)) {
613  xmask |= GCFillRule;
614  xgval.fill_rule = gval.fFillRule; // ident mapping
615  }
616  if ((mask & kGCTile)) {
617  xmask |= GCTile;
618  xgval.tile = (Pixmap) gval.fTile;
619  }
620  if ((mask & kGCStipple)) {
621  xmask |= GCStipple;
622  xgval.stipple = (Pixmap) gval.fStipple;
623  }
624  if ((mask & kGCTileStipXOrigin)) {
625  xmask |= GCTileStipXOrigin;
626  xgval.ts_x_origin = gval.fTsXOrigin;
627  }
628  if ((mask & kGCTileStipYOrigin)) {
629  xmask |= GCTileStipYOrigin;
630  xgval.ts_y_origin = gval.fTsYOrigin;
631  }
632  if ((mask & kGCFont)) {
633  if (!fHasXft) {
634  xmask |= GCFont;
635  xgval.font = (Font) gval.fFont;
636  }
637  }
638  if ((mask & kGCSubwindowMode)) {
639  xmask |= GCSubwindowMode;
640  xgval.subwindow_mode = gval.fSubwindowMode; // ident mapping
641  }
642  if ((mask & kGCGraphicsExposures)) {
643  xmask |= GCGraphicsExposures;
644  xgval.graphics_exposures = (Bool) gval.fGraphicsExposures;
645  }
646  if ((mask & kGCClipXOrigin)) {
647  xmask |= GCClipXOrigin;
648  xgval.clip_x_origin = gval.fClipXOrigin;
649  }
650  if ((mask & kGCClipYOrigin)) {
651  xmask |= GCClipYOrigin;
652  xgval.clip_y_origin = gval.fClipYOrigin;
653  }
654  if ((mask & kGCClipMask)) {
655  xmask |= GCClipMask;
656  xgval.clip_mask = (Pixmap) gval.fClipMask;
657  }
658  if ((mask & kGCDashOffset)) {
659  xmask |= GCDashOffset;
660  xgval.dash_offset = gval.fDashOffset;
661  }
662  if ((mask & kGCDashList)) {
663  xmask |= GCDashList;
664  xgval.dashes = gval.fDashes[0];
665  }
666  if ((mask & kGCArcMode)) {
667  xmask |= GCArcMode;
668  xgval.arc_mode = gval.fArcMode; // ident mapping
669  }
670 
671  } else {
672  // map XValues to GCValues_t
673  Mask_t mask = 0;
674 
675  if ((xmask & GCFunction)) {
676  mask |= kGCFunction;
677  gval.fFunction = (EGraphicsFunction) xgval.function; // ident mapping
678  }
679  if ((xmask & GCPlaneMask)) {
680  mask |= kGCPlaneMask;
681  gval.fPlaneMask = xgval.plane_mask;
682  }
683  if ((xmask & GCForeground)) {
684  mask |= kGCForeground;
685  gval.fForeground = xgval.foreground;
686  }
687  if ((xmask & GCBackground)) {
688  mask |= kGCBackground;
689  gval.fBackground = xgval.background;
690  }
691  if ((xmask & GCLineWidth)) {
692  mask |= kGCLineWidth;
693  gval.fLineWidth = xgval.line_width;
694  }
695  if ((xmask & GCLineStyle)) {
696  mask |= kGCLineStyle;
697  gval.fLineStyle = xgval.line_style; // ident mapping
698  }
699  if ((xmask & GCCapStyle)) {
700  mask |= kGCCapStyle;
701  gval.fCapStyle = xgval.cap_style; // ident mapping
702  }
703  if ((xmask & GCJoinStyle)) {
704  mask |= kGCJoinStyle;
705  gval.fJoinStyle = xgval.join_style; // ident mapping
706  }
707  if ((xmask & GCFillStyle)) {
708  mask |= kGCFillStyle;
709  gval.fFillStyle = xgval.fill_style; // ident mapping
710  }
711  if ((xmask & GCFillRule)) {
712  mask |= kGCFillRule;
713  gval.fFillRule = xgval.fill_rule; // ident mapping
714  }
715  if ((xmask & GCTile)) {
716  mask |= kGCTile;
717  gval.fTile = (Pixmap_t) xgval.tile;
718  }
719  if ((xmask & GCStipple)) {
720  mask |= kGCStipple;
721  gval.fStipple = (Pixmap_t) xgval.stipple;
722  }
723  if ((xmask & GCTileStipXOrigin)) {
724  mask |= kGCTileStipXOrigin;
725  gval.fTsXOrigin = xgval.ts_x_origin;
726  }
727  if ((xmask & GCTileStipYOrigin)) {
728  mask |= kGCTileStipYOrigin;
729  gval.fTsYOrigin = xgval.ts_y_origin;
730  }
731  if ((xmask & GCFont)) {
732  mask |= kGCFont;
733  gval.fFont = (FontH_t) xgval.font;
734  }
735  if ((xmask & GCSubwindowMode)) {
736  mask |= kGCSubwindowMode;
737  gval.fSubwindowMode = xgval.subwindow_mode; // ident mapping
738  }
739  if ((xmask & GCGraphicsExposures)) {
740  mask |= kGCGraphicsExposures;
741  gval.fGraphicsExposures = (Bool_t) xgval.graphics_exposures;
742  }
743  if ((xmask & GCClipXOrigin)) {
744  mask |= kGCClipXOrigin;
745  gval.fClipXOrigin = xgval.clip_x_origin;
746  }
747  if ((xmask & GCClipYOrigin)) {
748  mask |= kGCClipYOrigin;
749  gval.fClipYOrigin = xgval.clip_y_origin;
750  }
751  if ((xmask & GCClipMask)) {
752  mask |= kGCClipMask;
753  gval.fClipMask = (Pixmap_t) xgval.clip_mask;
754  }
755  if ((xmask & GCDashOffset)) {
756  mask |= kGCDashOffset;
757  gval.fDashOffset = xgval.dash_offset;
758  }
759  if ((xmask & GCDashList)) {
760  mask |= kGCDashList;
761  gval.fDashes[0] = xgval.dashes;
762  gval.fDashLen = 1;
763  }
764  if ((xmask & GCArcMode)) {
765  mask |= kGCArcMode;
766  gval.fArcMode = xgval.arc_mode; // ident mapping
767  }
768  gval.fMask = mask;
769  }
770 }
771 
772 ////////////////////////////////////////////////////////////////////////////////
773 /// Get window attributes and return filled in attributes structure.
774 
776 {
777  if (!id) return;
778 
779  XWindowAttributes xattr;
780 
781  XGetWindowAttributes((Display*)fDisplay, id, &xattr);
782 
783  attr.fX = xattr.x;
784  attr.fY = xattr.y;
785  attr.fWidth = xattr.width;
786  attr.fHeight = xattr.height;
787  attr.fBorderWidth = xattr.border_width;
788  attr.fDepth = xattr.depth;
789  attr.fVisual = xattr.visual;
790  attr.fRoot = (Window_t) xattr.root;
791  if (xattr.c_class == InputOutput) attr.fClass = kInputOutput;
792  if (xattr.c_class == InputOnly) attr.fClass = kInputOnly;
793  attr.fBitGravity = xattr.bit_gravity; // assume ident mapping (rdm)
794  attr.fWinGravity = xattr.win_gravity; // assume ident mapping (rdm)
795  if (xattr.backing_store == NotUseful) attr.fBackingStore = kNotUseful;
796  if (xattr.backing_store == WhenMapped) attr.fBackingStore = kWhenMapped;
797  if (xattr.backing_store == Always) attr.fBackingStore = kAlways;
798  attr.fBackingPlanes = xattr.backing_planes;
799  attr.fBackingPixel = xattr.backing_pixel;
800  attr.fSaveUnder = (Bool_t) xattr.save_under;
801  if ((Window) id == fRootWin)
802  attr.fColormap = (Colormap_t) fColormap;
803  else
804  attr.fColormap = (Colormap_t) xattr.colormap;
805  attr.fMapInstalled = (Bool_t) xattr.map_installed;
806  attr.fMapState = xattr.map_state; // ident mapping
807  attr.fAllEventMasks = xattr.all_event_masks; // not ident, but not used by GUI classes
808  attr.fYourEventMask = xattr.your_event_mask; // not ident, but not used by GUI classes
809  attr.fDoNotPropagateMask = xattr.do_not_propagate_mask;
810  attr.fOverrideRedirect = (Bool_t) xattr.override_redirect;
811  attr.fScreen = xattr.screen;
812 }
813 
814 ////////////////////////////////////////////////////////////////////////////////
815 /// Open connection to display server (if such a thing exist on the
816 /// current platform). On X11 this method returns on success the X
817 /// display socket descriptor (> 0), 0 in case of batch mode and < 0
818 /// in case of failure (cannot connect to display dpyName). It also
819 /// initializes the TGX11 class via Init(). Called from TGClient ctor.
820 
821 Int_t TGX11::OpenDisplay(const char *dpyName)
822 {
823 #ifdef _REENTRANT
824  // In some cases there can be problems due to XInitThreads, like when
825  // using Qt, so we allow for it to be turned off
826  if (gEnv->GetValue("X11.XInitThread", 1)) {
827  // Must be very first call before any X11 call !!
828  if (!XInitThreads())
829  Warning("OpenDisplay", "system has no X11 thread support");
830  }
831 #endif
832 
833  Display *dpy;
834  if (!(dpy = XOpenDisplay(dpyName)))
835  return -1;
836 
837  // Set custom X11 error handlers
838  XSetErrorHandler(RootX11ErrorHandler);
839  XSetIOErrorHandler(RootX11IOErrorHandler);
840 
841  if (gEnv->GetValue("X11.Sync", 0))
842  XSynchronize(dpy, 1);
843 
844  // Init the GX11 class, sets a.o. fDisplay.
845  if (!Init(dpy))
846  return -1;
847 
848  return ConnectionNumber(dpy);
849 }
850 
851 ////////////////////////////////////////////////////////////////////////////////
852 /// Close connection to display server.
853 
855 {
856  XCloseDisplay((Display*)fDisplay);
857  fDisplay = 0;
858 }
859 
860 ////////////////////////////////////////////////////////////////////////////////
861 /// Returns handle to display (might be useful in some cases where
862 /// direct X11 manipulation outside of TVirtualX is needed, e.g. GL
863 /// interface).
864 
866 {
867  return (Display_t) fDisplay;
868 }
869 
870 ////////////////////////////////////////////////////////////////////////////////
871 /// Returns handle to visual (might be useful in some cases where
872 /// direct X11 manipulation outside of TVirtualX is needed, e.g. GL
873 /// interface).
874 
876 {
877  return (Visual_t) fVisual;
878 }
879 
880 ////////////////////////////////////////////////////////////////////////////////
881 /// Returns handle to colormap (might be useful in some cases where
882 /// direct X11 manipulation outside of TVirtualX is needed, e.g. GL
883 /// interface).
884 
886 {
887  return (Colormap_t) fColormap;
888 }
889 
890 ////////////////////////////////////////////////////////////////////////////////
891 /// Returns screen number (might be useful in some cases where
892 /// direct X11 manipulation outside of TVirtualX is needed, e.g. GL
893 /// interface).
894 
896 {
897  return fScreenNumber;
898 }
899 
900 ////////////////////////////////////////////////////////////////////////////////
901 /// Returns depth of screen (number of bit planes). Equivalent to
902 /// GetPlanes().
903 
905 {
906  return fDepth;
907 }
908 
909 ////////////////////////////////////////////////////////////////////////////////
910 /// Return atom handle for atom_name. If it does not exist
911 /// create it if only_if_exist is false. Atoms are used to communicate
912 /// between different programs (i.e. window manager) via the X server.
913 
914 Atom_t TGX11::InternAtom(const char *atom_name, Bool_t only_if_exist)
915 {
916  Atom a = XInternAtom((Display*)fDisplay, (char *)atom_name, (Bool)only_if_exist);
917 
918  if (a == None) return kNone;
919  return (Atom_t) a;
920 }
921 
922 ////////////////////////////////////////////////////////////////////////////////
923 /// Return handle to the default root window created when calling
924 /// XOpenDisplay().
925 
927 {
928  return (Window_t) fRootWin;
929 }
930 
931 ////////////////////////////////////////////////////////////////////////////////
932 /// Return the parent of the window.
933 
935 {
936  if (!id) return (Window_t)0;
937 
938  Window root, parent;
939  Window *children = 0;
940  UInt_t nchildren;
941 
942  XQueryTree((Display*)fDisplay, (Window) id, &root, &parent, &children, &nchildren);
943 
944  if (children) XFree(children);
945 
946  return (Window_t) parent;
947 }
948 
949 
950 ////////////////////////////////////////////////////////////////////////////////
951 /// Load font and query font. If font is not found 0 is returned,
952 /// otherwise an opaque pointer to the FontStruct_t.
953 /// Free the loaded font using DeleteFont().
954 
955 FontStruct_t TGX11::LoadQueryFont(const char *font_name)
956 {
957  XFontStruct *fs = XLoadQueryFont((Display*)fDisplay, (char *)font_name);
958  return (FontStruct_t) fs;
959 }
960 
961 ////////////////////////////////////////////////////////////////////////////////
962 /// Return handle to font described by font structure.
963 
965 {
966  if (fs) {
967  XFontStruct *fss = (XFontStruct *)fs;
968  return fss->fid;
969  }
970  return 0;
971 }
972 
973 ////////////////////////////////////////////////////////////////////////////////
974 /// Explicitly delete font structure obtained with LoadQueryFont().
975 
977 {
978  if (fDisplay) XFreeFont((Display*)fDisplay, (XFontStruct *) fs);
979 }
980 
981 ////////////////////////////////////////////////////////////////////////////////
982 /// Create a graphics context using the values set in gval (but only for
983 /// those entries that are in the mask).
984 
986 {
987  RXGCValues xgval;
988  ULong_t xmask = 0;
989 
990  if (gval)
991  MapGCValues(*gval, xmask, xgval);
992 
993  if (!id || ((Drawable) id == fRootWin))
994  id = (Drawable_t) fVisRootWin;
995 
996  GC gc = XCreateGC((Display*)fDisplay, (Drawable) id, xmask, &xgval);
997 
998  if (gval && (gval->fMask & kGCFont))
999  MapGCFont((GContext_t)gc, gval->fFont);
1000 
1001  return (GContext_t) gc;
1002 }
1003 
1004 ////////////////////////////////////////////////////////////////////////////////
1005 /// Change entries in an existing graphics context, gc, by values from gval.
1006 
1008 {
1009  RXGCValues xgval;
1010  ULong_t xmask = 0;
1011 
1012  if (gval)
1013  MapGCValues(*gval, xmask, xgval);
1014 
1015  XChangeGC((Display*)fDisplay, (GC) gc, xmask, &xgval);
1016 
1017  if (gval && (gval->fMask & kGCFont))
1018  MapGCFont((GContext_t)gc, gval->fFont);
1019 }
1020 
1021 ////////////////////////////////////////////////////////////////////////////////
1022 /// Copies graphics context from org to dest. Only the values specified
1023 /// in mask are copied. If mask = 0 then copy all fields. Both org and
1024 /// dest must exist.
1025 
1027 {
1028  GCValues_t gval;
1029  RXGCValues xgval;
1030  ULong_t xmask;
1031 
1032  if (!mask) {
1033  // in this case copy all fields
1034  mask = kMaxUInt;
1035  }
1036 
1037  gval.fMask = mask; // only set fMask used to convert to xmask
1038  MapGCValues(gval, xmask, xgval);
1039 
1040  XCopyGC((Display*)fDisplay, (GC) org, xmask, (GC) dest);
1041 }
1042 
1043 ////////////////////////////////////////////////////////////////////////////////
1044 /// Explicitly delete a graphics context.
1045 
1047 {
1048  // Protection against deletion of global TGGC objects, which are
1049  // destructed after fDisplay has been closed.
1050  if (fDisplay)
1051  XFreeGC((Display*)fDisplay, (GC) gc);
1052 }
1053 
1054 ////////////////////////////////////////////////////////////////////////////////
1055 /// Create cursor handle (just return cursor from cursor pool fCursors).
1056 
1058 {
1059  return (Cursor_t) fCursors[cursor];
1060 }
1061 
1062 ////////////////////////////////////////////////////////////////////////////////
1063 /// Set the specified cursor.
1064 
1066 {
1067  if (!id) return;
1068 
1069  XDefineCursor((Display*)fDisplay, (Window) id, (Cursor) curid);
1070 }
1071 
1072 ////////////////////////////////////////////////////////////////////////////////
1073 /// Creates a pixmap of the width and height you specified
1074 /// and returns a pixmap ID that identifies it.
1075 
1077 {
1078  return (Pixmap_t) XCreatePixmap((Display*)fDisplay, (Drawable) (id ? id : fRootWin), w, h, fDepth);
1079 }
1080 
1081 ////////////////////////////////////////////////////////////////////////////////
1082 /// Create a pixmap from bitmap data. Ones will get foreground color and
1083 /// zeroes background color.
1084 
1085 Pixmap_t TGX11::CreatePixmap(Drawable_t id, const char *bitmap,
1086  UInt_t width, UInt_t height, ULong_t forecolor, ULong_t backcolor,
1087  Int_t depth)
1088 {
1089  return (Pixmap_t) XCreatePixmapFromBitmapData((Display*)fDisplay, (id ? id : fRootWin), (char *)bitmap,
1090  width, height, forecolor, backcolor, depth);
1091 }
1092 
1093 ////////////////////////////////////////////////////////////////////////////////
1094 /// Create a bitmap (i.e. pixmap with depth 1) from the bitmap data.
1095 
1096 Pixmap_t TGX11::CreateBitmap(Drawable_t id, const char *bitmap,
1097  UInt_t width, UInt_t height)
1098 {
1099  return (Pixmap_t) XCreateBitmapFromData((Display*)fDisplay, (id ? id : fRootWin), (char *)bitmap,
1100  width, height);
1101 }
1102 
1103 ////////////////////////////////////////////////////////////////////////////////
1104 /// Explicitly delete pixmap resource.
1105 
1107 {
1108  if (fDisplay) XFreePixmap((Display*)fDisplay, (Pixmap) pmap);
1109 }
1110 
1111 ////////////////////////////////////////////////////////////////////////////////
1112 /// Map a PictureAttributes_t to a XpmAttributes structure. If toxpm is
1113 /// kTRUE map from attr to xpmattr, else map the other way.
1114 
1116  Bool_t toxpm)
1117 {
1118 #ifdef XpmVersion
1119  if (toxpm) {
1120  Mask_t mask = attr.fMask;
1121  ULong_t xmask = 0;
1122 
1123  if ((mask & kPAColormap)) {
1124  xmask |= XpmColormap;
1125  xpmattr.colormap = (Colormap)attr.fColormap;
1126  }
1127  if ((mask & kPADepth)) {
1128  xmask |= XpmDepth;
1129  xpmattr.depth = attr.fDepth;
1130  }
1131  if ((mask & kPASize)) {
1132  xmask |= XpmSize;
1133  xpmattr.width = attr.fWidth;
1134  xpmattr.height = attr.fHeight;
1135  }
1136  if ((mask & kPAHotspot)) {
1137  xmask |= XpmHotspot;
1138  xpmattr.x_hotspot = attr.fXHotspot;
1139  xpmattr.y_hotspot = attr.fYHotspot;
1140  }
1141  if ((mask & kPAReturnPixels)) {
1142  xmask |= XpmReturnPixels;
1143  xpmattr.pixels = 0; // output parameters
1144  xpmattr.npixels = 0;
1145  }
1146  if ((mask & kPACloseness)) {
1147  xmask |= XpmCloseness;
1148  xpmattr.closeness = attr.fCloseness;
1149  }
1150  xpmattr.valuemask = xmask;
1151  } else {
1152  ULong_t xmask = xpmattr.valuemask;
1153  Mask_t mask = 0;
1154 
1155  attr.fPixels = 0;
1156  attr.fNpixels = 0;
1157 
1158  if ((xmask & XpmColormap)) {
1159  mask |= kPAColormap;
1160  attr.fColormap = (Colormap_t)xpmattr.colormap;
1161  mask |= kPADepth;
1162  attr.fDepth = xpmattr.depth;
1163  }
1164  if ((xmask & XpmSize)) {
1165  mask |= kPASize;
1166  attr.fWidth = xpmattr.width;
1167  attr.fHeight = xpmattr.height;
1168  }
1169  if ((xmask & XpmHotspot)) {
1170  mask |= kPAHotspot;
1171  attr.fXHotspot = xpmattr.x_hotspot;
1172  attr.fYHotspot = xpmattr.y_hotspot;
1173  }
1174  if ((xmask & XpmReturnPixels)) {
1175  mask |= kPAReturnPixels;
1176  if (xpmattr.npixels) {
1177  attr.fPixels = new ULong_t[xpmattr.npixels];
1178  for (UInt_t i = 0; i < xpmattr.npixels; i++)
1179  attr.fPixels[i] = xpmattr.pixels[i];
1180  attr.fNpixels = xpmattr.npixels;
1181  }
1182  }
1183  if ((xmask & XpmCloseness)) {
1184  mask |= kPACloseness;
1185  attr.fCloseness = xpmattr.closeness;
1186  }
1187  attr.fMask = mask;
1188  }
1189 #endif
1190 }
1191 
1192 ////////////////////////////////////////////////////////////////////////////////
1193 /// Create a picture pixmap from data on file. The picture attributes
1194 /// are used for input and output. Returns kTRUE in case of success,
1195 /// kFALSE otherwise. If mask does not exist it is set to kNone.
1196 
1198  Pixmap_t &pict, Pixmap_t &pict_mask,
1200 {
1201  if (strstr(filename, ".gif") || strstr(filename, ".GIF")) {
1202  pict = ReadGIF(0, 0, filename, id);
1203  pict_mask = kNone;
1204  attr.fDepth = fDepth;
1205  Int_t dummy;
1206  GetWindowSize(pict, dummy, dummy, attr.fWidth, attr.fHeight);
1207  return kTRUE;
1208  }
1209 
1210 #ifdef XpmVersion
1211  RXpmAttributes xpmattr;
1212 
1213  MapPictureAttributes(attr, xpmattr);
1214 
1215  // make sure pixel depth of pixmap is the same as in the visual
1216  if ((Drawable) id == fRootWin && fRootWin != fVisRootWin) {
1217  xpmattr.valuemask |= XpmDepth;
1218  xpmattr.depth = fDepth;
1219  }
1220 
1221  Int_t res = XpmReadFileToPixmap((Display*)fDisplay, (id ? id : fRootWin), (char*)filename,
1222  (Pixmap*)&pict, (Pixmap*)&pict_mask, &xpmattr);
1223 
1224  MapPictureAttributes(attr, xpmattr, kFALSE);
1225  XpmFreeAttributes(&xpmattr);
1226 
1227  if (res == XpmSuccess || res == XpmColorError)
1228  return kTRUE;
1229 
1230  if (pict) {
1231  XFreePixmap((Display*)fDisplay, (Pixmap)pict);
1232  pict = kNone;
1233  }
1234  if (pict_mask) {
1235  XFreePixmap((Display*)fDisplay, (Pixmap)pict_mask);
1236  pict_mask = kNone;
1237  }
1238 #else
1239  Error("CreatePictureFromFile", "cannot get picture, not compiled with Xpm");
1240 #endif
1241 
1242  return kFALSE;
1243 }
1244 
1245 ////////////////////////////////////////////////////////////////////////////////
1246 /// Create a picture pixmap from data. The picture attributes
1247 /// are used for input and output. Returns kTRUE in case of success,
1248 /// kFALSE otherwise. If mask does not exist it is set to kNone.
1249 
1251  Pixmap_t &pict_mask, PictureAttributes_t &attr)
1252 {
1253 #ifdef XpmVersion
1254  RXpmAttributes xpmattr;
1255 
1256  MapPictureAttributes(attr, xpmattr);
1257 
1258  // make sure pixel depth of pixmap is the same as in the visual
1259  if ((Drawable) id == fRootWin && fRootWin != fVisRootWin) {
1260  xpmattr.valuemask |= XpmDepth;
1261  xpmattr.depth = fDepth;
1262  }
1263 
1264  Int_t res = XpmCreatePixmapFromData((Display*)fDisplay, (id ? id : fRootWin), data, (Pixmap*)&pict,
1265  (Pixmap*)&pict_mask, &xpmattr);
1266 
1267  MapPictureAttributes(attr, xpmattr, kFALSE);
1268  XpmFreeAttributes(&xpmattr);
1269 
1270  if (res == XpmSuccess || res == XpmColorError)
1271  return kTRUE;
1272 
1273  if (pict) {
1274  XFreePixmap((Display*)fDisplay, (Pixmap)pict);
1275  pict = kNone;
1276  }
1277  if (pict_mask) {
1278  XFreePixmap((Display*)fDisplay, (Pixmap)pict_mask);
1279  pict_mask = kNone;
1280  }
1281 #else
1282  Error("CreatePictureFromData", "cannot get picture, not compiled with Xpm");
1283 #endif
1284 
1285  return kFALSE;
1286 }
1287 
1288 ////////////////////////////////////////////////////////////////////////////////
1289 /// Read picture data from file and store in ret_data. Returns kTRUE in
1290 /// case of success, kFALSE otherwise.
1291 
1292 Bool_t TGX11::ReadPictureDataFromFile(const char *filename, char ***ret_data)
1293 {
1294 #ifdef XpmVersion
1295  if (XpmReadFileToData((char*)filename, ret_data) == XpmSuccess)
1296  return kTRUE;
1297 #else
1298  Error("ReadPictureFromDataFile", "cannot get picture, not compiled with Xpm");
1299 #endif
1300  return kFALSE;
1301 }
1302 
1303 ////////////////////////////////////////////////////////////////////////////////
1304 /// Delete picture data created by the function ReadPictureDataFromFile.
1305 
1307 {
1308 #ifdef XpmVersion
1309  // some older libXpm's don't have this function and it is typically
1310  // implemented with a simple free()
1311  // XpmFree(data);
1312  free(data);
1313 #endif
1314 }
1315 
1316 ////////////////////////////////////////////////////////////////////////////////
1317 /// Specify a dash pattern. Offset defines the phase of the pattern.
1318 /// Each element in the dash_list array specifies the length (in pixels)
1319 /// of a segment of the pattern. N defines the length of the list.
1320 
1321 void TGX11::SetDashes(GContext_t gc, Int_t offset, const char *dash_list, Int_t n)
1322 {
1323  XSetDashes((Display*)fDisplay, (GC) gc, offset, (char *)dash_list, n);
1324 }
1325 
1326 ////////////////////////////////////////////////////////////////////////////////
1327 /// Map a ColorStruct_t to a XColor structure.
1328 
1329 void TGX11::MapColorStruct(ColorStruct_t *color, RXColor &xcolor)
1330 {
1331  xcolor.pixel = color->fPixel;
1332  xcolor.red = color->fRed;
1333  xcolor.green = color->fGreen;
1334  xcolor.blue = color->fBlue;
1335  xcolor.flags = color->fMask; //ident mapping
1336 }
1337 
1338 ////////////////////////////////////////////////////////////////////////////////
1339 /// Parse string cname containing color name, like "green" or "#00FF00".
1340 /// It returns a filled in ColorStruct_t. Returns kFALSE in case parsing
1341 /// failed, kTRUE in case of success. On success, the ColorStruct_t
1342 /// fRed, fGreen and fBlue fields are all filled in and the mask is set
1343 /// for all three colors, but fPixel is not set.
1344 
1345 Bool_t TGX11::ParseColor(Colormap_t cmap, const char *cname, ColorStruct_t &color)
1346 {
1347  XColor xc;
1348 
1349  if (XParseColor((Display*)fDisplay, (Colormap)cmap, (char *)cname, &xc)) {
1350  color.fPixel = 0;
1351  color.fRed = xc.red;
1352  color.fGreen = xc.green;
1353  color.fBlue = xc.blue;
1354  color.fMask = kDoRed | kDoGreen | kDoBlue;
1355  return kTRUE;
1356  }
1357  return kFALSE;
1358 }
1359 
1360 ////////////////////////////////////////////////////////////////////////////////
1361 /// Find and allocate a color cell according to the color values specified
1362 /// in the ColorStruct_t. If no cell could be allocated it returns kFALSE,
1363 /// otherwise kTRUE.
1364 
1366 {
1367  RXColor xc;
1368 
1369  MapColorStruct(&color, xc);
1370 
1371  color.fPixel = 0;
1372  if (AllocColor((Colormap)cmap, &xc)) {
1373  color.fPixel = xc.pixel;
1374  return kTRUE;
1375  }
1376 
1377  return kFALSE;
1378 }
1379 
1380 ////////////////////////////////////////////////////////////////////////////////
1381 /// Fill in the primary color components for a specific pixel value.
1382 /// On input fPixel should be set on return the fRed, fGreen and
1383 /// fBlue components will be set.
1384 
1386 {
1387  XColor xc;
1388 
1389  xc.pixel = color.fPixel;
1390 
1391  // still very slight dark shift ??
1392  //QueryColors((Colormap)cmap, &xc, 1);
1393  //printf("1 xc.red = %u, xc.green = %u, xc.blue = %u\n", xc.red, xc.green, xc.blue);
1394  XQueryColor((Display*)fDisplay, (Colormap)cmap, &xc);
1395  //printf("2 xc.red = %u, xc.green = %u, xc.blue = %u\n", xc.red, xc.green, xc.blue);
1396 
1397  color.fRed = xc.red;
1398  color.fGreen = xc.green;
1399  color.fBlue = xc.blue;
1400 }
1401 
1402 ////////////////////////////////////////////////////////////////////////////////
1403 /// Free color cell with specified pixel value.
1404 
1406 {
1407  if (fRedDiv == -1)
1408  XFreeColors((Display*)fDisplay, (Colormap)cmap, &pixel, 1, 0);
1409 }
1410 
1411 ////////////////////////////////////////////////////////////////////////////////
1412 /// Returns number of pending events.
1413 
1415 {
1416  if (!fDisplay) return 0;
1417  return XPending((Display*)fDisplay);
1418 }
1419 
1420 ////////////////////////////////////////////////////////////////////////////////
1421 /// Copies first pending event from event queue to Event_t structure
1422 /// and removes event from queue. Not all of the event fields are valid
1423 /// for each event type, except fType and fWindow.
1424 
1426 {
1427  XNextEvent((Display*)fDisplay, (XEvent*)fXEvent);
1428 
1429  // fill in Event_t
1430  MapEvent(event, fXEvent, kFALSE);
1431 }
1432 
1433 ////////////////////////////////////////////////////////////////////////////////
1434 /// Map modifier key state to or from X.
1435 
1436 void TGX11::MapModifierState(UInt_t &state, UInt_t &xstate, Bool_t tox)
1437 {
1438  if (tox) {
1439  xstate = 0;
1440  if ((state & kKeyShiftMask))
1441  xstate |= ShiftMask;
1442  if ((state & kKeyLockMask))
1443  xstate |= LockMask;
1444  if ((state & kKeyControlMask))
1445  xstate |= ControlMask;
1446  if ((state & kKeyMod1Mask))
1447  xstate |= Mod1Mask;
1448  if ((state & kKeyMod2Mask))
1449  xstate |= Mod2Mask;
1450  if ((state & kKeyMod3Mask))
1451  xstate |= Mod3Mask;
1452  if ((state & kKeyMod4Mask))
1453  xstate |= Mod4Mask;
1454  if ((state & kKeyMod5Mask))
1455  xstate |= Mod5Mask;
1456  if ((state & kButton1Mask))
1457  xstate |= Button1Mask;
1458  if ((state & kButton2Mask))
1459  xstate |= Button2Mask;
1460  if ((state & kButton3Mask))
1461  xstate |= Button3Mask;
1462  if ((state & kAnyModifier))
1463  xstate |= AnyModifier; // or should it be = instead of |= ?
1464  } else {
1465  state = 0;
1466  if ((xstate & ShiftMask))
1467  state |= kKeyShiftMask;
1468  if ((xstate & LockMask))
1469  state |= kKeyLockMask;
1470  if ((xstate & ControlMask))
1471  state |= kKeyControlMask;
1472  if ((xstate & Mod1Mask))
1473  state |= kKeyMod1Mask;
1474  if ((xstate & Mod2Mask))
1475  state |= kKeyMod2Mask;
1476  if ((xstate & Mod3Mask))
1477  state |= kKeyMod3Mask;
1478  if ((xstate & Mod4Mask))
1479  state |= kKeyMod4Mask;
1480  if ((xstate & Mod5Mask))
1481  state |= kKeyMod5Mask;
1482  if ((xstate & Button1Mask))
1483  state |= kButton1Mask;
1484  if ((xstate & Button2Mask))
1485  state |= kButton2Mask;
1486  if ((xstate & Button3Mask))
1487  state |= kButton3Mask;
1488  if ((xstate & AnyModifier))
1489  state |= kAnyModifier; // idem
1490  }
1491 }
1492 
1493 ////////////////////////////////////////////////////////////////////////////////
1494 /// Map Event_t structure to XEvent structure. If tox is false
1495 /// map the other way.
1496 
1497 void TGX11::MapEvent(Event_t &ev, void *xevi, Bool_t tox)
1498 {
1499  XEvent &xev = *(XEvent *)xevi;
1500 
1501  if (tox) {
1502  // map from Event_t to XEvent
1503  xev.type = 0;
1504  if (ev.fType == kGKeyPress) xev.type = KeyPress;
1505  if (ev.fType == kKeyRelease) xev.type = KeyRelease;
1506  if (ev.fType == kButtonPress) xev.type = ButtonPress;
1507  if (ev.fType == kButtonRelease) xev.type = ButtonRelease;
1508  if (ev.fType == kMotionNotify) xev.type = MotionNotify;
1509  if (ev.fType == kEnterNotify) xev.type = EnterNotify;
1510  if (ev.fType == kLeaveNotify) xev.type = LeaveNotify;
1511  if (ev.fType == kFocusIn) xev.type = FocusIn;
1512  if (ev.fType == kFocusOut) xev.type = FocusOut;
1513  if (ev.fType == kExpose) xev.type = Expose;
1514  if (ev.fType == kConfigureNotify) xev.type = ConfigureNotify;
1515  if (ev.fType == kMapNotify) xev.type = MapNotify;
1516  if (ev.fType == kUnmapNotify) xev.type = UnmapNotify;
1517  if (ev.fType == kDestroyNotify) xev.type = DestroyNotify;
1518  if (ev.fType == kClientMessage) xev.type = ClientMessage;
1519  if (ev.fType == kSelectionClear) xev.type = SelectionClear;
1520  if (ev.fType == kSelectionRequest) xev.type = SelectionRequest;
1521  if (ev.fType == kSelectionNotify) xev.type = SelectionNotify;
1522  if (ev.fType == kColormapNotify) xev.type = ColormapNotify;
1523 
1524  xev.xany.window = (Window) ev.fWindow;
1525  xev.xany.send_event = (Bool) ev.fSendEvent;
1526  xev.xany.display = (Display*)fDisplay;
1527 
1528  if (ev.fType == kGKeyPress || ev.fType == kKeyRelease) {
1529  xev.xkey.time = (Time) ev.fTime;
1530  xev.xkey.x = ev.fX;
1531  xev.xkey.y = ev.fY;
1532  xev.xkey.x_root = ev.fXRoot;
1533  xev.xkey.y_root = ev.fYRoot;
1534  MapModifierState(ev.fState, xev.xkey.state, kTRUE); // key mask
1535  xev.xkey.keycode = ev.fCode; // key code
1536  }
1537  if (ev.fType == kSelectionNotify) {
1538  xev.xselection.time = (Time) ev.fTime;
1539  xev.xselection.requestor = (Window) ev.fUser[0];
1540  xev.xselection.selection = (Atom) ev.fUser[1];
1541  xev.xselection.target = (Atom) ev.fUser[2];
1542  xev.xselection.property = (Atom) ev.fUser[3];
1543  }
1544  if (ev.fType == kClientMessage) {
1545  xev.xclient.message_type = ev.fHandle;
1546  xev.xclient.format = ev.fFormat;
1547  xev.xclient.data.l[0] = ev.fUser[0];
1548  if (sizeof(ev.fUser[0]) > 4) {
1549  SplitLong(ev.fUser[1], xev.xclient.data.l[1], xev.xclient.data.l[3]);
1550  SplitLong(ev.fUser[2], xev.xclient.data.l[2], xev.xclient.data.l[4]);
1551  } else {
1552  xev.xclient.data.l[1] = ev.fUser[1];
1553  xev.xclient.data.l[2] = ev.fUser[2];
1554  xev.xclient.data.l[3] = ev.fUser[3];
1555  xev.xclient.data.l[4] = ev.fUser[4];
1556  }
1557  }
1558  } else {
1559  // map from XEvent to Event_t
1560  ev.fType = kOtherEvent;
1561  if (xev.type == KeyPress) ev.fType = kGKeyPress;
1562  if (xev.type == KeyRelease) ev.fType = kKeyRelease;
1563  if (xev.type == ButtonPress) ev.fType = kButtonPress;
1564  if (xev.type == ButtonRelease) ev.fType = kButtonRelease;
1565  if (xev.type == MotionNotify) ev.fType = kMotionNotify;
1566  if (xev.type == EnterNotify) ev.fType = kEnterNotify;
1567  if (xev.type == LeaveNotify) ev.fType = kLeaveNotify;
1568  if (xev.type == FocusIn) ev.fType = kFocusIn;
1569  if (xev.type == FocusOut) ev.fType = kFocusOut;
1570  if (xev.type == Expose) ev.fType = kExpose;
1571  if (xev.type == GraphicsExpose) ev.fType = kExpose;
1572  if (xev.type == ConfigureNotify) ev.fType = kConfigureNotify;
1573  if (xev.type == MapNotify) ev.fType = kMapNotify;
1574  if (xev.type == UnmapNotify) ev.fType = kUnmapNotify;
1575  if (xev.type == DestroyNotify) ev.fType = kDestroyNotify;
1576  if (xev.type == ClientMessage) ev.fType = kClientMessage;
1577  if (xev.type == SelectionClear) ev.fType = kSelectionClear;
1578  if (xev.type == SelectionRequest) ev.fType = kSelectionRequest;
1579  if (xev.type == SelectionNotify) ev.fType = kSelectionNotify;
1580  if (xev.type == ColormapNotify) ev.fType = kColormapNotify;
1581 
1582  ev.fWindow = (Window_t) xev.xany.window;
1583  ev.fSendEvent = xev.xany.send_event ? kTRUE : kFALSE;
1584 
1585  if (ev.fType == kGKeyPress || ev.fType == kKeyRelease) {
1586  ev.fTime = (Time_t) xev.xkey.time;
1587  ev.fX = xev.xkey.x;
1588  ev.fY = xev.xkey.y;
1589  ev.fXRoot = xev.xkey.x_root;
1590  ev.fYRoot = xev.xkey.y_root;
1591  MapModifierState(ev.fState, xev.xkey.state, kFALSE); // key mask
1592  ev.fCode = xev.xkey.keycode; // key code
1593  ev.fUser[0] = xev.xkey.subwindow; // child window
1594  }
1595  if (ev.fType == kButtonPress || ev.fType == kButtonRelease) {
1596  ev.fTime = (Time_t) xev.xbutton.time;
1597  ev.fX = xev.xbutton.x;
1598  ev.fY = xev.xbutton.y;
1599  ev.fXRoot = xev.xbutton.x_root;
1600  ev.fYRoot = xev.xbutton.y_root;
1601  MapModifierState(ev.fState, xev.xbutton.state, kFALSE); // button mask
1602  ev.fCode = xev.xbutton.button; // button code
1603  ev.fUser[0] = xev.xbutton.subwindow; // child window
1604  }
1605  if (ev.fType == kMotionNotify) {
1606  ev.fTime = (Time_t) xev.xmotion.time;
1607  ev.fX = xev.xmotion.x;
1608  ev.fY = xev.xmotion.y;
1609  ev.fXRoot = xev.xmotion.x_root;
1610  ev.fYRoot = xev.xmotion.y_root;
1611  MapModifierState(ev.fState, xev.xmotion.state, kFALSE); // key or button mask
1612  ev.fUser[0] = xev.xmotion.subwindow; // child window
1613  }
1614  if (ev.fType == kEnterNotify || ev.fType == kLeaveNotify) {
1615  ev.fTime = (Time_t) xev.xcrossing.time;
1616  ev.fX = xev.xcrossing.x;
1617  ev.fY = xev.xcrossing.y;
1618  ev.fXRoot = xev.xcrossing.x_root;
1619  ev.fYRoot = xev.xcrossing.y_root;
1620  ev.fCode = xev.xcrossing.mode; // NotifyNormal, NotifyGrab, NotifyUngrab
1621  MapModifierState(ev.fState, xev.xcrossing.state, kFALSE); // key or button mask
1622  }
1623  if (ev.fType == kFocusIn || ev.fType == kFocusOut) {
1624  // check this when porting to Win32 (see also TGTextEntry::HandleFocusChange)
1625  ev.fCode = xev.xfocus.mode; // NotifyNormal, NotifyGrab, NotifyUngrab
1626  ev.fState = xev.xfocus.detail; // NotifyPointer et al.
1627  }
1628  if (ev.fType == kExpose) {
1629  ev.fX = xev.xexpose.x;
1630  ev.fY = xev.xexpose.y;
1631  ev.fWidth = xev.xexpose.width; // width and
1632  ev.fHeight = xev.xexpose.height; // height of exposed area
1633  ev.fCount = xev.xexpose.count; // number of expose events still to come
1634  }
1635  if (ev.fType == kConfigureNotify) {
1636  ev.fX = xev.xconfigure.x;
1637  ev.fY = xev.xconfigure.y;
1638  ev.fWidth = xev.xconfigure.width;
1639  ev.fHeight = xev.xconfigure.height;
1640  }
1641  if (ev.fType == kMapNotify || ev.fType == kUnmapNotify) {
1642  ev.fHandle = xev.xmap.window; // window to be (un)mapped
1643  }
1644  if (ev.fType == kDestroyNotify) {
1645  ev.fHandle = xev.xdestroywindow.window; // window to be destroyed
1646  }
1647  if (ev.fType == kClientMessage) {
1648  ev.fHandle = xev.xclient.message_type;
1649  ev.fFormat = xev.xclient.format;
1650  ev.fUser[0] = xev.xclient.data.l[0];
1651  if (sizeof(ev.fUser[0]) > 4) {
1652  AsmLong(xev.xclient.data.l[1], xev.xclient.data.l[3], ev.fUser[1]);
1653  AsmLong(xev.xclient.data.l[2], xev.xclient.data.l[4], ev.fUser[2]);
1654  } else {
1655  ev.fUser[1] = xev.xclient.data.l[1];
1656  ev.fUser[2] = xev.xclient.data.l[2];
1657  ev.fUser[3] = xev.xclient.data.l[3];
1658  ev.fUser[4] = xev.xclient.data.l[4];
1659  }
1660  }
1661  if (ev.fType == kSelectionClear) {
1662  ev.fUser[0] = xev.xselectionclear.selection;
1663  }
1664  if (ev.fType == kSelectionRequest) {
1665  ev.fTime = (Time_t) xev.xselectionrequest.time;
1666  ev.fUser[0] = xev.xselectionrequest.requestor;
1667  ev.fUser[1] = xev.xselectionrequest.selection;
1668  ev.fUser[2] = xev.xselectionrequest.target;
1669  ev.fUser[3] = xev.xselectionrequest.property;
1670  }
1671  if (ev.fType == kSelectionNotify) {
1672  ev.fTime = (Time_t) xev.xselection.time;
1673  ev.fUser[0] = xev.xselection.requestor;
1674  ev.fUser[1] = xev.xselection.selection;
1675  ev.fUser[2] = xev.xselection.target;
1676  ev.fUser[3] = xev.xselection.property;
1677  }
1678  if (ev.fType == kColormapNotify) {
1679  ev.fHandle = xev.xcolormap.colormap;
1680  ev.fCode = xev.xcolormap.state; // ColormapUninstalled, ColormapInstalled
1681  ev.fState = xev.xcolormap.c_new; // true if new colormap
1682  }
1683  }
1684 }
1685 
1686 ////////////////////////////////////////////////////////////////////////////////
1687 /// Sound bell. Percent is loudness from -100% .. 100%.
1688 
1689 void TGX11::Bell(Int_t percent)
1690 {
1691  XBell((Display*)fDisplay, percent);
1692 }
1693 
1694 ////////////////////////////////////////////////////////////////////////////////
1695 /// Copy a drawable (i.e. pixmap) to another drawable (pixmap, window).
1696 /// The graphics context gc will be used and the source will be copied
1697 /// from src_x,src_y,src_x+width,src_y+height to dest_x,dest_y.
1698 
1700  Int_t src_x, Int_t src_y, UInt_t width, UInt_t height,
1701  Int_t dest_x, Int_t dest_y)
1702 {
1703  if (!src || !dest) return;
1704 
1705  XCopyArea((Display*)fDisplay, src, dest, (GC) gc, src_x, src_y, width, height,
1706  dest_x, dest_y);
1707 }
1708 
1709 ////////////////////////////////////////////////////////////////////////////////
1710 /// Change window attributes.
1711 
1713 {
1714  if (!id) return;
1715 
1716  RXSetWindowAttributes xattr;
1717  ULong_t xmask = 0;
1718 
1719  if (attr)
1720  MapSetWindowAttributes(attr, xmask, xattr);
1721 
1722  XChangeWindowAttributes((Display*)fDisplay, (Window) id, xmask, &xattr);
1723 
1724  if (attr && (attr->fMask & kWABorderWidth))
1725  XSetWindowBorderWidth((Display*)fDisplay, (Window) id, attr->fBorderWidth);
1726 }
1727 
1728 ////////////////////////////////////////////////////////////////////////////////
1729 /// This function alters the property for the specified window and
1730 /// causes the X server to generate a PropertyNotify event on that
1731 /// window.
1732 
1734  UChar_t *data, Int_t len)
1735 {
1736  if (!id) return;
1737 
1738  XChangeProperty((Display*)fDisplay, (Window) id, (Atom) property, (Atom) type,
1739  8, PropModeReplace, data, len);
1740 }
1741 
1742 ////////////////////////////////////////////////////////////////////////////////
1743 /// Draw a line.
1744 
1746 {
1747  if (!id) return;
1748 
1749  XDrawLine((Display*)fDisplay, (Drawable) id, (GC) gc, x1, y1, x2, y2);
1750 }
1751 
1752 ////////////////////////////////////////////////////////////////////////////////
1753 /// Clear a window area to the background color.
1754 
1756 {
1757  if (!id) return;
1758 
1759  XClearArea((Display*)fDisplay, (Window) id, x, y, w, h, False);
1760 }
1761 
1762 ////////////////////////////////////////////////////////////////////////////////
1763 /// Check if there is for window "id" an event of type "type". If there
1764 /// is fill in the event structure and return true. If no such event
1765 /// return false.
1766 
1768 {
1769  if (!id) return kFALSE;
1770 
1771  Event_t tev;
1772  XEvent xev;
1773 
1774  tev.fCode = 0;
1775  tev.fState = 0;
1776  tev.fWindow = 0;
1777  tev.fUser[0] = tev.fUser[1] = tev.fUser[2] = tev.fUser[3] = tev.fUser[4] = 0;
1778  tev.fCount = 0;
1779  tev.fFormat = 0;
1780  tev.fHandle = 0;
1781  tev.fSendEvent = 0;
1782  tev.fTime = 0;
1783  tev.fX = tev.fY = 0;
1784  tev.fXRoot = tev.fYRoot = 0;
1785  tev.fType = type;
1786  MapEvent(tev, &xev);
1787 
1788  Bool r = XCheckTypedWindowEvent((Display*)fDisplay, (Window) id, xev.type, &xev);
1789 
1790  if (r) MapEvent(ev, &xev, kFALSE);
1791 
1792  return r ? kTRUE : kFALSE;
1793 }
1794 
1795 ////////////////////////////////////////////////////////////////////////////////
1796 /// Send event ev to window id.
1797 
1799 {
1800  if (!ev || !id) return;
1801 
1802  XEvent xev;
1803 
1804  MapEvent(*ev, &xev);
1805 
1806  XSendEvent((Display*)fDisplay, (Window) id, False, None, &xev);
1807 }
1808 
1809 ////////////////////////////////////////////////////////////////////////////////
1810 /// Tell WM to send message when window is closed via WM.
1811 
1813 {
1814  if (!id) return;
1815 
1816  XSetWMProtocols((Display*)fDisplay, (Window) id, &gWM_DELETE_WINDOW, 1);
1817 }
1818 
1819 ////////////////////////////////////////////////////////////////////////////////
1820 /// Turn key auto repeat on or off.
1821 
1823 {
1824  if (on)
1825  XAutoRepeatOn((Display*)fDisplay);
1826  else
1827  XAutoRepeatOff((Display*)fDisplay);
1828 }
1829 
1830 ////////////////////////////////////////////////////////////////////////////////
1831 /// Establish passive grab on a certain key. That is, when a certain key
1832 /// keycode is hit while certain modifier's (Shift, Control, Meta, Alt)
1833 /// are active then the keyboard will be grabbed for window id.
1834 /// When grab is false, ungrab the keyboard for this key and modifier.
1835 
1836 void TGX11::GrabKey(Window_t id, Int_t keycode, UInt_t modifier, Bool_t grab)
1837 {
1838 // if (!id) return;
1839 
1840  UInt_t xmod;
1841 
1842  MapModifierState(modifier, xmod);
1843 
1844  if (grab)
1845  XGrabKey((Display*)fDisplay, keycode, xmod, (Window) id, True,
1846  GrabModeAsync, GrabModeAsync);
1847  else
1848  XUngrabKey((Display*)fDisplay, keycode, xmod, (Window) id);
1849 }
1850 
1851 ////////////////////////////////////////////////////////////////////////////////
1852 /// Establish passive grab on a certain mouse button. That is, when a
1853 /// certain mouse button is hit while certain modifier's (Shift, Control,
1854 /// Meta, Alt) are active then the mouse will be grabbed for window id.
1855 /// When grab is false, ungrab the mouse button for this button and modifier.
1856 
1857 void TGX11::GrabButton(Window_t id, EMouseButton button, UInt_t modifier,
1858  UInt_t evmask, Window_t confine, Cursor_t cursor,
1859  Bool_t grab)
1860 {
1861  if (!id) return;
1862 
1863  UInt_t xmod;
1864 
1865  MapModifierState(modifier, xmod);
1866 
1867  if (grab) {
1868  UInt_t xevmask;
1869  MapEventMask(evmask, xevmask);
1870 
1871  XGrabButton((Display*)fDisplay, button, xmod, (Window) id, True, xevmask,
1872  GrabModeAsync, GrabModeAsync, (Window) confine,
1873  (Cursor) cursor);
1874  } else
1875  XUngrabButton((Display*)fDisplay, button, xmod, (Window) id);
1876 }
1877 
1878 ////////////////////////////////////////////////////////////////////////////////
1879 /// Establish an active pointer grab. While an active pointer grab is in
1880 /// effect, further pointer events are only reported to the grabbing
1881 /// client window.
1882 
1883 void TGX11::GrabPointer(Window_t id, UInt_t evmask, Window_t confine,
1884  Cursor_t cursor, Bool_t grab, Bool_t owner_events)
1885 {
1886 // if (!id) return;
1887 
1888  if (grab) {
1889  UInt_t xevmask;
1890  MapEventMask(evmask, xevmask);
1891 
1892  XGrabPointer((Display*)fDisplay, (Window) id, (Bool) owner_events,
1893  xevmask, GrabModeAsync, GrabModeAsync, (Window) confine,
1894  (Cursor) cursor, CurrentTime);
1895  } else
1896  XUngrabPointer((Display*)fDisplay, CurrentTime);
1897 }
1898 
1899 ////////////////////////////////////////////////////////////////////////////////
1900 /// Set window name.
1901 
1903 {
1904  if (!id) return;
1905 
1906  XTextProperty wname;
1907 
1908  if (XStringListToTextProperty(&name, 1, &wname) == 0) {
1909  Error("SetWindowName", "cannot allocate window name \"%s\"", name);
1910  return;
1911  }
1912  XSetWMName((Display*)fDisplay, (Window) id, &wname);
1913  XFree(wname.value);
1914 }
1915 
1916 ////////////////////////////////////////////////////////////////////////////////
1917 /// Set window icon name.
1918 
1920 {
1921  if (!id) return;
1922 
1923  XTextProperty wname;
1924 
1925  if (XStringListToTextProperty(&name, 1, &wname) == 0) {
1926  Error("SetIconName", "cannot allocate icon name \"%s\"", name);
1927  return;
1928  }
1929  XSetWMIconName((Display*)fDisplay, (Window) id, &wname);
1930  XFree(wname.value);
1931 }
1932 
1933 ////////////////////////////////////////////////////////////////////////////////
1934 /// Set pixmap the WM can use when the window is iconized.
1935 
1937 {
1938  if (!id) return;
1939 
1940  XWMHints hints;
1941 
1942  hints.flags = IconPixmapHint;
1943  hints.icon_pixmap = (Pixmap) pic;
1944 
1945  XSetWMHints((Display*)fDisplay, (Window) id, &hints);
1946 }
1947 
1948 ////////////////////////////////////////////////////////////////////////////////
1949 /// Set the windows class and resource name.
1950 
1951 void TGX11::SetClassHints(Window_t id, char *className, char *resourceName)
1952 {
1953  if (!id) return;
1954 
1955  XClassHint class_hints;
1956 
1957  class_hints.res_class = className;
1958  class_hints.res_name = resourceName;
1959  XSetClassHint((Display*)fDisplay, (Window) id, &class_hints);
1960 }
1961 
1962 ////////////////////////////////////////////////////////////////////////////////
1963 /// Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
1964 
1966 {
1967  if (!id) return;
1968 
1969  MWMHintsProperty_t prop;
1970 
1971  prop.fDecorations = value;
1972  prop.fFunctions = funcs;
1973  prop.fInputMode = input;
1974  prop.fFlags = kMWMHintsDecorations | kMWMHintsFunctions | kMWMHintsInputMode;
1975 
1976  XChangeProperty((Display*)fDisplay, (Window) id, gMOTIF_WM_HINTS, gMOTIF_WM_HINTS, 32,
1977  PropModeReplace, (UChar_t *)&prop, kPropMWMHintElements);
1978 }
1979 
1980 ////////////////////////////////////////////////////////////////////////////////
1981 /// Tell the window manager the desired window position.
1982 
1984 {
1985  if (!id) return;
1986 
1987  XSizeHints hints;
1988 
1989  hints.flags = USPosition | PPosition;
1990  hints.x = x;
1991  hints.y = y;
1992 
1993  XSetWMNormalHints((Display*)fDisplay, (Window) id, &hints);
1994 }
1995 
1996 ////////////////////////////////////////////////////////////////////////////////
1997 /// Tell the window manager the desired window size.
1998 
2000 {
2001  if (!id) return;
2002 
2003  XSizeHints hints;
2004 
2005  hints.flags = USSize | PSize | PBaseSize;
2006  hints.width = hints.base_width = w;
2007  hints.height = hints.base_height = h;
2008 
2009  XSetWMNormalHints((Display*)fDisplay, (Window) id, &hints);
2010 }
2011 
2012 ////////////////////////////////////////////////////////////////////////////////
2013 /// Give the window manager minimum and maximum size hints. Also
2014 /// specify via winc and hinc the resize increments.
2015 
2017  UInt_t wmax, UInt_t hmax,
2018  UInt_t winc, UInt_t hinc)
2019 {
2020  if (!id) return;
2021 
2022  XSizeHints hints;
2023 
2024  hints.flags = PMinSize | PMaxSize | PResizeInc;
2025  hints.min_width = (Int_t)wmin;
2026  hints.max_width = (Int_t)wmax;
2027  hints.min_height = (Int_t)hmin;
2028  hints.max_height = (Int_t)hmax;
2029  hints.width_inc = (Int_t)winc;
2030  hints.height_inc = (Int_t)hinc;
2031 
2032  XSetWMNormalHints((Display*)fDisplay, (Window) id, &hints);
2033 }
2034 
2035 ////////////////////////////////////////////////////////////////////////////////
2036 /// Set the initial state of the window. Either kNormalState or kIconicState.
2037 
2039 {
2040  if (!id) return;
2041 
2042  XWMHints hints;
2043  Int_t xstate = NormalState;
2044 
2045  if (state == kNormalState)
2046  xstate = NormalState;
2047  if (state == kIconicState)
2048  xstate = IconicState;
2049 
2050  hints.flags = StateHint;
2051  hints.initial_state = xstate;
2052 
2053  XSetWMHints((Display*)fDisplay, (Window) id, &hints);
2054 }
2055 
2056 ////////////////////////////////////////////////////////////////////////////////
2057 /// Tell window manager that window is a transient window of main.
2058 
2060 {
2061  if (!id) return;
2062 
2063  XSetTransientForHint((Display*)fDisplay, (Window) id, (Window) main_id);
2064 }
2065 
2066 ////////////////////////////////////////////////////////////////////////////////
2067 /// Draw a string using a specific graphics context in position (x,y).
2068 
2070  const char *s, Int_t len)
2071 {
2072  if (!id) return;
2073 
2074  XDrawString((Display*)fDisplay, (Drawable) id, (GC) gc, x, y, (char *) s, len);
2075 }
2076 
2077 ////////////////////////////////////////////////////////////////////////////////
2078 /// Return length of string in pixels. Size depends on font.
2079 
2080 Int_t TGX11::TextWidth(FontStruct_t font, const char *s, Int_t len)
2081 {
2082  return XTextWidth((XFontStruct*) font, (char*) s, len);
2083 }
2084 
2085 ////////////////////////////////////////////////////////////////////////////////
2086 /// Return some font properties.
2087 
2088 void TGX11::GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent)
2089 {
2090  XFontStruct *f = (XFontStruct *) font;
2091 
2092  max_ascent = f->max_bounds.ascent;
2093  max_descent = f->max_bounds.descent;
2094 }
2095 
2096 ////////////////////////////////////////////////////////////////////////////////
2097 /// Get current values from graphics context gc. Which values of the
2098 /// context to get is encoded in the GCValues::fMask member. If fMask = 0
2099 /// then copy all fields.
2100 
2102 {
2103  RXGCValues xgval;
2104  ULong_t xmask;
2105 
2106  if (!gval.fMask) {
2107  // in this case copy all fields
2108  gval.fMask = kMaxUInt;
2109  }
2110 
2111  MapGCValues(gval, xmask, xgval);
2112 
2113  XGetGCValues((Display*)fDisplay, (GC) gc, xmask, &xgval);
2114 
2115  MapGCValues(gval, xmask, xgval, kFALSE);
2116 }
2117 
2118 ////////////////////////////////////////////////////////////////////////////////
2119 /// Retrieve associated font structure once we have the font handle.
2120 /// Free returned FontStruct_t using FreeFontStruct().
2121 
2123 {
2124  XFontStruct *fs;
2125 
2126  fs = XQueryFont((Display*)fDisplay, (Font) fh);
2127 
2128  return (FontStruct_t) fs;
2129 }
2130 
2131 ////////////////////////////////////////////////////////////////////////////////
2132 /// Free font structure returned by GetFontStruct().
2133 
2135 {
2136  // in XFree86 4.0 XFreeFontInfo() is broken, ok again in 4.0.1
2137  static int xfree86_400 = -1;
2138  if (xfree86_400 == -1) {
2139  if (strstr(XServerVendor((Display*)fDisplay), "XFree86") &&
2140  XVendorRelease((Display*)fDisplay) == 4000)
2141  xfree86_400 = 1;
2142  else
2143  xfree86_400 = 0;
2144  }
2145 
2146  if (xfree86_400 == 0)
2147  XFreeFontInfo(0, (XFontStruct *) fs, 1);
2148 }
2149 
2150 ////////////////////////////////////////////////////////////////////////////////
2151 /// Clear window.
2152 
2154 {
2155  if (!id) return;
2156 
2157  XClearWindow((Display*)fDisplay, (Window) id);
2158 }
2159 
2160 ////////////////////////////////////////////////////////////////////////////////
2161 /// Convert a keysym to the appropriate keycode. For example keysym is
2162 /// a letter and keycode is the matching keyboard key (which is dependent
2163 /// on the current keyboard mapping).
2164 
2166 {
2167  UInt_t xkeysym;
2168  MapKeySym(keysym, xkeysym);
2169 
2170  return XKeysymToKeycode((Display*)fDisplay, xkeysym);
2171 }
2172 
2173 ////////////////////////////////////////////////////////////////////////////////
2174 /// Draw a filled rectangle. Filling is done according to the gc.
2175 
2177 {
2178  if (!id) return;
2179 
2180  XFillRectangle((Display*)fDisplay, (Drawable) id, (GC) gc, x, y, w, h);
2181 }
2182 
2183 ////////////////////////////////////////////////////////////////////////////////
2184 /// Draw a rectangle outline.
2185 
2187 {
2188  if (!id) return;
2189 
2190  XDrawRectangle((Display*)fDisplay, (Drawable) id, (GC) gc, x, y, w, h);
2191 }
2192 
2193 ////////////////////////////////////////////////////////////////////////////////
2194 /// Draws multiple line segments. Each line is specified by a pair of points.
2195 
2197 {
2198  if (!id) return;
2199 
2200  XDrawSegments((Display*)fDisplay, (Drawable) id, (GC) gc, (XSegment *) seg, nseg);
2201 }
2202 
2203 ////////////////////////////////////////////////////////////////////////////////
2204 /// Defines which input events the window is interested in. By default
2205 /// events are propagated up the window stack. This mask can also be
2206 /// set at window creation time via the SetWindowAttributes_t::fEventMask
2207 /// attribute.
2208 
2210 {
2211  if (!id) return;
2212 
2213  UInt_t xevmask;
2214 
2215  MapEventMask(evmask, xevmask);
2216 
2217  XSelectInput((Display*)fDisplay, (Window) id, xevmask);
2218 }
2219 
2220 ////////////////////////////////////////////////////////////////////////////////
2221 /// Returns the window id of the window having the input focus.
2222 
2224 {
2225  Window focus;
2226  int return_to;
2227 
2228  XGetInputFocus((Display*)fDisplay, &focus, &return_to);
2229  return (Window_t) focus;
2230 }
2231 
2232 ////////////////////////////////////////////////////////////////////////////////
2233 /// Set keyboard input focus to window id.
2234 
2236 {
2237  if (!id) return;
2238 
2239  XWindowAttributes xattr;
2240 
2241  XGetWindowAttributes((Display*)fDisplay, (Window) id, &xattr);
2242 
2243  if (xattr.map_state == IsViewable)
2244  XSetInputFocus((Display*)fDisplay, (Window) id, RevertToParent, CurrentTime);
2245 }
2246 
2247 ////////////////////////////////////////////////////////////////////////////////
2248 /// Returns the window id of the current owner of the primary selection.
2249 /// That is the window in which, for example some text is selected.
2250 
2252 {
2253  return (Window_t) XGetSelectionOwner((Display*)fDisplay, XA_PRIMARY);
2254 }
2255 
2256 ////////////////////////////////////////////////////////////////////////////////
2257 /// Makes the window id the current owner of the primary selection.
2258 /// That is the window in which, for example some text is selected.
2259 
2261 {
2262  if (!id) return;
2263 
2264  XSetSelectionOwner((Display*)fDisplay, XA_PRIMARY, id, CurrentTime);
2265 }
2266 
2267 ////////////////////////////////////////////////////////////////////////////////
2268 /// XConvertSelection() causes a SelectionRequest event to be sent to the
2269 /// current primary selection owner. This event specifies the selection
2270 /// property (primary selection), the format into which to convert that
2271 /// data before storing it (target = XA_STRING), the property in which
2272 /// the owner will place the information (sel_property), the window that
2273 /// wants the information (id), and the time of the conversion request
2274 /// (when).
2275 /// The selection owner responds by sending a SelectionNotify event, which
2276 /// confirms the selected atom and type.
2277 
2279 {
2280  if (!id) return;
2281 
2282  XConvertSelection((Display*)fDisplay, XA_PRIMARY, XA_STRING, (Atom) clipboard,
2283  (Window) id, (Time) when);
2284 }
2285 
2286 ////////////////////////////////////////////////////////////////////////////////
2287 /// Convert the keycode from the event structure to a key symbol (according
2288 /// to the modifiers specified in the event structure and the current
2289 /// keyboard mapping). In buf a null terminated ASCII string is returned
2290 /// representing the string that is currently mapped to the key code.
2291 
2292 void TGX11::LookupString(Event_t *event, char *buf, Int_t buflen, UInt_t &keysym)
2293 {
2294  XEvent xev;
2295  KeySym xkeysym;
2296 
2297  MapEvent(*event, &xev);
2298 
2299  int n = XLookupString(&xev.xkey, buf, buflen-1, &xkeysym, 0);
2300  if (n >= buflen)
2301  Error("LookupString", "buf too small, must be at least %d", n+1);
2302  else
2303  buf[n] = 0;
2304 
2305  UInt_t ks, xks = (UInt_t) xkeysym;
2306  MapKeySym(ks, xks, kFALSE);
2307  keysym = (Int_t) ks;
2308 }
2309 
2310 ////////////////////////////////////////////////////////////////////////////////
2311 /// Map to and from X key symbols. Keysym are the values returned by
2312 /// XLookUpString.
2313 
2314 void TGX11::MapKeySym(UInt_t &keysym, UInt_t &xkeysym, Bool_t tox)
2315 {
2316  if (tox) {
2317  xkeysym = XK_VoidSymbol;
2318  if (keysym < 127) {
2319  xkeysym = keysym;
2320  } else if (keysym >= kKey_F1 && keysym <= kKey_F35) {
2321  xkeysym = XK_F1 + (keysym - (UInt_t)kKey_F1); // function keys
2322  } else {
2323  for (int i = 0; gKeyMap[i].fKeySym; i++) { // any other keys
2324  if (keysym == (UInt_t) gKeyMap[i].fKeySym) {
2325  xkeysym = (UInt_t) gKeyMap[i].fXKeySym;
2326  break;
2327  }
2328  }
2329  }
2330  } else {
2331  keysym = kKey_Unknown;
2332  // commentary in X11/keysymdef says that X codes match ASCII
2333  if (xkeysym < 127) {
2334  keysym = xkeysym;
2335  } else if (xkeysym >= XK_F1 && xkeysym <= XK_F35) {
2336  keysym = kKey_F1 + (xkeysym - XK_F1); // function keys
2337  } else if (xkeysym >= XK_KP_0 && xkeysym <= XK_KP_9) {
2338  keysym = kKey_0 + (xkeysym - XK_KP_0); // numeric keypad keys
2339  } else {
2340  for (int i = 0; gKeyMap[i].fXKeySym; i++) { // any other keys
2341  if (xkeysym == gKeyMap[i].fXKeySym) {
2342  keysym = (UInt_t) gKeyMap[i].fKeySym;
2343  break;
2344  }
2345  }
2346  }
2347  }
2348 }
2349 
2350 ////////////////////////////////////////////////////////////////////////////////
2351 /// Get contents of paste buffer atom into string. If del is true delete
2352 /// the paste buffer afterwards.
2353 
2355  Bool_t del)
2356 {
2357  if (!id) return;
2358 
2359  Atom actual_type, property = (Atom) atom;
2360  int actual_format;
2361  ULong_t nitems, bytes_after, nread;
2362  unsigned char *data;
2363 
2364  nchar = 0;
2365  text = "";
2366 
2367  if (property == None) return;
2368 
2369  // get past buffer
2370  nread = 0;
2371  do {
2372  if (XGetWindowProperty((Display*)fDisplay, (Window) id, property,
2373  nread/4, 1024, (Bool)del,
2374  AnyPropertyType,
2375  &actual_type, &actual_format,
2376  &nitems, &bytes_after,
2377  (unsigned char **) &data)
2378  != Success)
2379  break;
2380 
2381  if (actual_type != XA_STRING) break;
2382 
2383  text.Insert((Int_t) nread, (const char *) data, (Int_t) nitems);
2384  nread += nitems;
2385  XFree(data);
2386 
2387  } while (bytes_after > 0);
2388 
2389  nchar = (Int_t) nread;
2390 }
2391 
2392 ////////////////////////////////////////////////////////////////////////////////
2393 /// TranslateCoordinates translates coordinates from the frame of
2394 /// reference of one window to another. If the point is contained
2395 /// in a mapped child of the destination, the id of that child is
2396 /// returned as well.
2397 
2399  Int_t src_y, Int_t &dest_x, Int_t &dest_y, Window_t &child)
2400 {
2401  if (!src || !dest) return;
2402 
2403  Window xchild;
2404 
2405  XTranslateCoordinates((Display*)fDisplay, (Window) src, (Window) dest, src_x,
2406  src_y, &dest_x, &dest_y, &xchild);
2407  child = (Window_t) xchild;
2408 }
2409 
2410 ////////////////////////////////////////////////////////////////////////////////
2411 /// Return geometry of window (should be called GetGeometry but signature
2412 /// already used).
2413 
2415 {
2416  if (!id) return;
2417 
2418  Window wdummy;
2419  UInt_t bdum, ddum;
2420 
2421  XGetGeometry((Display*)fDisplay, (Drawable) id, &wdummy, &x, &y, &w, &h, &bdum, &ddum);
2422 }
2423 
2424 ////////////////////////////////////////////////////////////////////////////////
2425 /// FillPolygon fills the region closed by the specified path.
2426 /// The path is closed automatically if the last point in the list does
2427 /// not coincide with the first point. All point coordinates are
2428 /// treated as relative to the origin. For every pair of points
2429 /// inside the polygon, the line segment connecting them does not
2430 /// intersect the path.
2431 
2433 {
2434  if (!id) return;
2435 
2436  XFillPolygon((Display*)fDisplay, (Window) id, (GC) gc, (XPoint *) points, npnt,
2437  Convex, CoordModeOrigin);
2438 }
2439 
2440 ////////////////////////////////////////////////////////////////////////////////
2441 /// Returns the root window the pointer is logically on and the pointer
2442 /// coordinates relative to the root window's origin.
2443 /// The pointer coordinates returned to win_x and win_y are relative to
2444 /// the origin of the specified window. In this case, QueryPointer returns
2445 /// the child that contains the pointer, if any, or else kNone to
2446 /// childw. QueryPointer returns the current logical state of the
2447 /// keyboard buttons and the modifier keys in mask.
2448 
2450  Int_t &root_x, Int_t &root_y, Int_t &win_x,
2451  Int_t &win_y, UInt_t &mask)
2452 {
2453  if (!id) return;
2454 
2455  Window xrootw, xchildw;
2456  UInt_t xmask;
2457 
2458  XQueryPointer((Display*)fDisplay, (Window) id, &xrootw, &xchildw,
2459  &root_x, &root_y, &win_x, &win_y, &xmask);
2460 
2461  rootw = (Window_t) xrootw;
2462  childw = (Window_t) xchildw;
2463 
2464  MapModifierState(mask, xmask, kFALSE);
2465 }
2466 
2467 ////////////////////////////////////////////////////////////////////////////////
2468 /// Set foreground color in graphics context (shortcut for ChangeGC with
2469 /// only foreground mask set).
2470 
2472 {
2473  XSetForeground((Display*)fDisplay, (GC) gc, foreground);
2474 }
2475 
2476 ////////////////////////////////////////////////////////////////////////////////
2477 /// Set clipping rectangles in graphics context. X, Y specify the origin
2478 /// of the rectangles. Recs specifies an array of rectangles that define
2479 /// the clipping mask and n is the number of rectangles.
2480 
2482 {
2483  XSetClipRectangles((Display*)fDisplay, (GC) gc, x, y, (XRectangle *) recs, n, Unsorted);
2484 }
2485 
2486 ////////////////////////////////////////////////////////////////////////////////
2487 /// Flush (mode = 0, default) or synchronize (mode = 1) X output buffer.
2488 /// Flush flushes output buffer. Sync flushes buffer and waits till all
2489 /// requests have been processed by X server.
2490 
2492 {
2493  if (mode == 0)
2494  XFlush((Display*)fDisplay);
2495  if (mode == 1)
2496  XSync((Display*)fDisplay, False);
2497 }
2498 
2499 ////////////////////////////////////////////////////////////////////////////////
2500 /// Create a new empty region.
2501 
2503 {
2504  return (Region_t) XCreateRegion();
2505 }
2506 
2507 ////////////////////////////////////////////////////////////////////////////////
2508 /// Destroy region.
2509 
2511 {
2512  XDestroyRegion((Region)reg);
2513 }
2514 
2515 ////////////////////////////////////////////////////////////////////////////////
2516 /// Union of rectangle with a region.
2517 
2519 {
2520  XRectangle *r = (XRectangle *) rect; // 1 on 1 mapping
2521  XUnionRectWithRegion(r, (Region) src, (Region) dest);
2522 }
2523 
2524 ////////////////////////////////////////////////////////////////////////////////
2525 /// Create region for the polygon defined by the points array.
2526 /// If winding is true use WindingRule else EvenOddRule as fill rule.
2527 
2529 {
2530  XPoint *p = (XPoint *) points;
2531  return (Region_t) XPolygonRegion(p, np, winding ? WindingRule : EvenOddRule);
2532 }
2533 
2534 ////////////////////////////////////////////////////////////////////////////////
2535 /// Compute the union of rega and regb and return result region.
2536 /// The output region may be the same result region.
2537 
2539 {
2540  XUnionRegion((Region) rega, (Region) regb, (Region) result);
2541 }
2542 
2543 ////////////////////////////////////////////////////////////////////////////////
2544 /// Compute the intersection of rega and regb and return result region.
2545 /// The output region may be the same as the result region.
2546 
2548 {
2549  XIntersectRegion((Region) rega, (Region) regb, (Region) result);
2550 }
2551 
2552 ////////////////////////////////////////////////////////////////////////////////
2553 /// Subtract rega from regb.
2554 
2556 {
2557  XSubtractRegion((Region) rega, (Region) regb, (Region) result);
2558 }
2559 
2560 ////////////////////////////////////////////////////////////////////////////////
2561 /// Calculate the difference between the union and intersection of
2562 /// two regions.
2563 
2565 {
2566  XXorRegion((Region) rega, (Region) regb, (Region) result);
2567 }
2568 
2569 ////////////////////////////////////////////////////////////////////////////////
2570 /// Return true if the region is empty.
2571 
2573 {
2574  return (Bool_t) XEmptyRegion((Region) reg);
2575 }
2576 
2577 ////////////////////////////////////////////////////////////////////////////////
2578 /// Returns true if the point x,y is in the region.
2579 
2581 {
2582  return (Bool_t) XPointInRegion((Region) reg, x, y);
2583 }
2584 
2585 ////////////////////////////////////////////////////////////////////////////////
2586 /// Returns true if two regions are equal.
2587 
2589 {
2590  return (Bool_t) XEqualRegion((Region) rega, (Region) regb);
2591 }
2592 
2593 ////////////////////////////////////////////////////////////////////////////////
2594 /// Return smallest enclosing rectangle.
2595 
2597 {
2598  XClipBox((Region) reg, (XRectangle*) rect);
2599 }
2600 
2601 ////////////////////////////////////////////////////////////////////////////////
2602 /// Return list of font names matching fontname regexp, like "-*-times-*".
2603 
2604 char **TGX11::ListFonts(const char *fontname, Int_t max, Int_t &count)
2605 {
2606  char **fontlist;
2607  Int_t fontcount = 0;
2608  fontlist = XListFonts((Display*)fDisplay, (char *)fontname, max, &fontcount);
2609  count = fontcount;
2610  return fontlist;
2611 }
2612 
2613 ////////////////////////////////////////////////////////////////////////////////
2614 /// Free list of font names.
2615 
2616 void TGX11::FreeFontNames(char **fontlist)
2617 {
2618  XFreeFontNames(fontlist);
2619 }
2620 
2621 ////////////////////////////////////////////////////////////////////////////////
2622 /// Create a client-side XImage. Returns handle to XImage.
2623 
2625 {
2626  Int_t bitmap_pad;
2627 
2628  if (fDepth <= 8)
2629  bitmap_pad = 8;
2630  else if (fDepth <= 16)
2631  bitmap_pad = 16;
2632  else
2633  bitmap_pad = 32;
2634 
2635  XImage *xim = XCreateImage((Display*)fDisplay, fVisual, fDepth, ZPixmap,
2636  0, 0, width, height, bitmap_pad, 0);
2637 
2638  // use calloc since Xlib will use free() in XDestroyImage
2639  if (xim) xim->data = (char *) calloc(xim->bytes_per_line * xim->height, 1);
2640 
2641  return (Drawable_t) xim;
2642 }
2643 
2644 ////////////////////////////////////////////////////////////////////////////////
2645 /// Get size of XImage img.
2646 
2647 void TGX11::GetImageSize(Drawable_t img, UInt_t &width, UInt_t &height)
2648 {
2649  width = ((XImage*)img)->width;
2650  height = ((XImage*)img)->height;
2651 }
2652 
2653 ////////////////////////////////////////////////////////////////////////////////
2654 /// Set pixel at specified location in XImage img.
2655 
2657 {
2658  XPutPixel((XImage*) img, x, y, pixel);
2659 }
2660 
2661 ////////////////////////////////////////////////////////////////////////////////
2662 /// Put (x,y,w,h) part of image img in window win at position dx,dy.
2663 
2665  Int_t dy, Int_t x, Int_t y, UInt_t w, UInt_t h)
2666 {
2667  if (!win) return;
2668 
2669  XPutImage((Display*)fDisplay, (Drawable) win, (GC) gc, (XImage*) img,
2670  x, y, dx, dy, w, h);
2671 }
2672 
2673 ////////////////////////////////////////////////////////////////////////////////
2674 /// Destroy XImage img.
2675 
2677 {
2678  XDestroyImage((XImage*) img);
2679 }
2680 
2681 ////////////////////////////////////////////////////////////////////////////////
2682 /// The Nonrectangular Window Shape Extension adds nonrectangular
2683 /// windows to the System.
2684 /// This allows for making shaped (partially transparent) windows
2685 
2687 {
2688  XShapeCombineMask((Display*)fDisplay, (Window) id, ShapeBounding, x, y,
2689  (Pixmap) mask, ShapeSet);
2690 }
2691 
2692 ////////////////////////////////////////////////////////////////////////////////
2693 /// Returns the width of the screen in millimeters.
2694 
2696 {
2697  return (UInt_t)WidthMMOfScreen(DefaultScreenOfDisplay((Display*)fDisplay));
2698 }
2699 
2700 ////////////////////////////////////////////////////////////////////////////////
2701 /// Deletes the specified property only if the property was defined on the
2702 /// specified window and causes the X server to generate a PropertyNotify
2703 /// event on the window unless the property does not exist.
2704 
2706 {
2707  XDeleteProperty((Display*)fDisplay, win, prop);
2708 }
2709 
2710 ////////////////////////////////////////////////////////////////////////////////
2711 /// Returns the actual type of the property; the actual format of the property;
2712 /// the number of 8-bit, 16-bit, or 32-bit items transferred; the number of
2713 /// bytes remaining to be read in the property; and a pointer to the data
2714 /// actually returned.
2715 
2717  Bool_t del, Atom_t req_type, Atom_t *act_type,
2718  Int_t *act_format, ULong_t *nitems, ULong_t *bytes,
2719  unsigned char **prop_list)
2720 {
2721  return XGetWindowProperty((Display*)fDisplay, win, prop, offset, length, del, req_type,
2722  act_type, act_format, nitems, bytes, prop_list);
2723 }
2724 
2725 ////////////////////////////////////////////////////////////////////////////////
2726 /// Changes the specified dynamic parameters if the pointer is actively
2727 /// grabbed by the client.
2728 
2730 {
2731  UInt_t xevmask;
2732  MapEventMask(mask, xevmask);
2733  if (cur == kNone)
2734  XChangeActivePointerGrab((Display*)fDisplay, xevmask, fCursors[kHand], CurrentTime);
2735  else
2736  XChangeActivePointerGrab((Display*)fDisplay, xevmask, cur, CurrentTime);
2737 }
2738 
2739 ////////////////////////////////////////////////////////////////////////////////
2740 /// Requests that the specified selection be converted to the specified
2741 /// target type.
2742 
2744  Atom_t &prop, Time_t &stamp)
2745 {
2746  XConvertSelection((Display*)fDisplay, sel, target, prop, win, stamp);
2747 }
2748 
2749 ////////////////////////////////////////////////////////////////////////////////
2750 /// Changes the owner and last-change time for the specified selection
2751 
2753 {
2754  return XSetSelectionOwner((Display*)fDisplay, sel, owner, CurrentTime);
2755 }
2756 
2757 ////////////////////////////////////////////////////////////////////////////////
2758 /// This function alters the property for the specified window and
2759 /// causes the X server to generate a PropertyNotify event on that
2760 /// window.
2761 
2763  Int_t format, UChar_t *data, Int_t len)
2764 {
2765  if (!id) return;
2766 
2767  XChangeProperty((Display*)fDisplay, (Window) id, (Atom) property, (Atom) type,
2768  format, PropModeReplace, data, len);
2769 }
2770 
2771 ////////////////////////////////////////////////////////////////////////////////
2772 /// Add XdndAware property and the list of drag and drop types to the
2773 /// Window win.
2774 
2775 void TGX11::SetDNDAware(Window_t win, Atom_t *typelist)
2776 {
2777  unsigned char version = 4;
2778  Atom_t dndaware = InternAtom("XdndAware", kFALSE);
2779  XChangeProperty((Display*)fDisplay, (Window) win, (Atom) dndaware, (Atom) XA_ATOM,
2780  32, PropModeReplace, (unsigned char *) &version, 1);
2781 
2782  if (typelist) {
2783  int n;
2784 
2785  for (n = 0; typelist[n]; n++) { }
2786  if (n > 0) {
2787  XChangeProperty((Display*)fDisplay, win, dndaware, XA_ATOM, 32, PropModeAppend,
2788  (unsigned char *) typelist, n);
2789  }
2790  }
2791 }
2792 
2793 ////////////////////////////////////////////////////////////////////////////////
2794 /// Add the list of drag and drop types to the Window win.
2795 
2797 {
2798  if (typelist) {
2799  int n;
2800  for (n = 0; typelist[n]; n++) { }
2801  if (n > 0) {
2802  XChangeProperty((Display*)fDisplay, win, prop, XA_ATOM, 32, PropModeAppend,
2803  (unsigned char *) typelist, n);
2804  }
2805  }
2806 }
2807 
2808 ////////////////////////////////////////////////////////////////////////////////
2809 /// Recursively search in the children of Window for a Window which is at
2810 /// location x, y and is DND aware, with a maximum depth of maxd.
2811 /// Possibility to exclude dragwin and input.
2812 
2814  int x, int y, int maxd)
2815 {
2816  WindowAttributes_t wattr;
2817  static Atom_t *dndTypeList = 0;
2818 
2819  if (dndTypeList == 0) {
2820  dndTypeList = new Atom_t[3];
2821  dndTypeList[0] = InternAtom("application/root", kFALSE);
2822  dndTypeList[1] = InternAtom("text/uri-list", kFALSE);
2823  dndTypeList[2] = 0;
2824  }
2825 
2826  if (maxd <= 0) return kNone;
2827 
2828  if (win == dragwin || win == input) return kNone;
2829 
2830  GetWindowAttributes(win, wattr);
2831  if (wattr.fMapState != kIsUnmapped &&
2832  x >= wattr.fX && x < wattr.fX + wattr.fWidth &&
2833  y >= wattr.fY && y < wattr.fY + wattr.fHeight) {
2834 
2835  if (IsDNDAware(win, dndTypeList)) return win;
2836 
2837  Window r, p, *children;
2838  UInt_t numch;
2839  int i;
2840 
2841  if (XQueryTree((Display*)fDisplay, win, &r, &p, &children, &numch)) {
2842  if (children && numch > 0) {
2843  r = kNone;
2844  // upon return from XQueryTree, children are listed in the current
2845  // stacking order, from bottom-most (first) to top-most (last)
2846  for (i = numch-1; i >= 0; --i) {
2847  r = FindRWindow((Window_t)children[i], dragwin, input,
2848  x - wattr.fX, y - wattr.fY, maxd-1);
2849  if (r != kNone) break;
2850  }
2851  XFree(children);
2852  if (r != kNone) return r;
2853  }
2854  return kNone; //win; // ?!?
2855  }
2856  }
2857  return kNone;
2858 }
2859 
2860 ////////////////////////////////////////////////////////////////////////////////
2861 /// Checks if Window win is DND aware, and knows any of the DND formats
2862 /// passed in argument.
2863 
2865 {
2866  Atom_t actual;
2867  Int_t format;
2868  ULong_t count, remaining;
2869  unsigned char *data = 0;
2870  Atom_t *types, *t;
2871  Int_t result = kTRUE;
2872  static Atom_t dndaware = kNone;
2873 
2874  if (win == kNone) return kFALSE;
2875 
2876  if (dndaware == kNone)
2877  dndaware = InternAtom("XdndAware", kFALSE);
2878 
2879  XGetWindowProperty((Display*)fDisplay, win, dndaware, 0, 0x8000000L, kFALSE,
2880  XA_ATOM, &actual, &format, &count, &remaining, &data);
2881 
2882  if ((actual != XA_ATOM) || (format != 32) || (count == 0) || !data) {
2883  if (data) XFree(data);
2884  return kFALSE;
2885  }
2886 
2887  types = (Atom_t *) data;
2888 
2889  if ((count > 1) && typelist) {
2890  result = kFALSE;
2891  for (t = typelist; *t; t++) {
2892  for (ULong_t j = 1; j < count; j++) {
2893  if (types[j] == *t) {
2894  result = kTRUE;
2895  break;
2896  }
2897  }
2898  if (result) break;
2899  }
2900  }
2901  XFree(data);
2902  return result;
2903 }
Int_t fClipXOrigin
Definition: GuiTypes.h:246
UShort_t fBlue
Definition: GuiTypes.h:315
void GetPasteBuffer(Window_t id, Atom_t atom, TString &text, Int_t &nchar, Bool_t del)
Get contents of paste buffer atom into string.
Definition: GX11Gui.cxx:2354
void GetGCValues(GContext_t gc, GCValues_t &gval)
Get current values from graphics context gc.
Definition: GX11Gui.cxx:2101
const Mask_t kKeyReleaseMask
Definition: GuiTypes.h:161
void * fDisplay
Pointer to display.
Definition: TGX11.h:130
Int_t fLineStyle
Definition: GuiTypes.h:231
Bool_t fSendEvent
Definition: GuiTypes.h:185
Handle_t FontStruct_t
Definition: GuiTypes.h:40
void MapRaised(Window_t id)
Map window on screen and put on top of all windows.
Definition: GX11Gui.cxx:249
void MapEvent(Event_t &ev, void *xev, Bool_t tox=kTRUE)
Map Event_t structure to XEvent structure.
Definition: GX11Gui.cxx:1497
void SetWMPosition(Window_t id, Int_t x, Int_t y)
Tell the window manager the desired window position.
Definition: GX11Gui.cxx:1983
void SendEvent(Window_t id, Event_t *ev)
Send event ev to window id.
Definition: GX11Gui.cxx:1798
Char_t fDashes[8]
Definition: GuiTypes.h:250
Int_t GetScreen() const
Returns screen number (might be useful in some cases where direct X11 manipulation outside of TVirtua...
Definition: GX11Gui.cxx:895
Int_t GetDepth() const
Returns depth of screen (number of bit planes).
Definition: GX11Gui.cxx:904
ULong_t fBackingPlanes
Definition: GuiTypes.h:103
void SetDashes(GContext_t gc, Int_t offset, const char *dash_list, Int_t n)
Specify a dash pattern.
Definition: GX11Gui.cxx:1321
Window_t 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 wtype)
Return handle to newly created X window.
Definition: GX11Gui.cxx:382
XID Drawable
Definition: TGX11.h:38
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:420
Pixmap_t fTile
Definition: GuiTypes.h:239
const Mask_t kColormapChangeMask
Definition: GuiTypes.h:172
void ChangeProperty(Window_t id, Atom_t property, Atom_t type, UChar_t *data, Int_t len)
This function alters the property for the specified window and causes the X server to generate a Prop...
Definition: GX11Gui.cxx:1733
void DeleteFont(FontStruct_t fs)
Explicitly delete font structure obtained with LoadQueryFont().
Definition: GX11Gui.cxx:976
void GrabKey(Window_t id, Int_t keycode, UInt_t modifier, Bool_t grab=kTRUE)
Establish passive grab on a certain key.
Definition: GX11Gui.cxx:1836
static Int_t RootX11IOErrorHandler(Display *)
Handle X11 I/O error (happens when connection to display server is broken).
Definition: GX11Gui.cxx:209
void MapColorStruct(ColorStruct_t *color, RXColor &xcolor)
Map a ColorStruct_t to a XColor structure.
Definition: GX11Gui.cxx:1329
void DeletePictureData(void *data)
Delete picture data created by the function ReadPictureDataFromFile.
Definition: GX11Gui.cxx:1306
EInitialState
Definition: GuiTypes.h:346
const Mask_t kButton2Mask
Definition: GuiTypes.h:205
Bool_t ReadPictureDataFromFile(const char *filename, char ***ret_data)
Read picture data from file and store in ret_data.
Definition: GX11Gui.cxx:1292
void PutImage(Int_t offset, Int_t itran, Int_t x0, Int_t y0, Int_t nx, Int_t ny, Int_t xmin, Int_t ymin, Int_t xmax, Int_t ymax, UChar_t *image, Drawable_t id)
Draw image.
Definition: TGX11.cxx:3197
Colormap_t GetColormap() const
Returns handle to colormap (might be useful in some cases where direct X11 manipulation outside of TV...
Definition: GX11Gui.cxx:885
FontStruct_t GetFontStruct(FontH_t fh)
Retrieve associated font structure once we have the font handle.
Definition: GX11Gui.cxx:2122
const Mask_t kKeyMod2Mask
Definition: GuiTypes.h:200
void SetDNDAware(Window_t, Atom_t *)
Add XdndAware property and the list of drag and drop types to the Window win.
Definition: GX11Gui.cxx:2775
char ** ListFonts(const char *fontname, Int_t max, Int_t &count)
Return list of font names matching fontname regexp, like "-*-times-*".
Definition: GX11Gui.cxx:2604
FontH_t fFont
Definition: GuiTypes.h:243
UInt_t Mask_t
Definition: GuiTypes.h:42
const Mask_t kGCFillRule
Definition: GuiTypes.h:296
void DrawLine(Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Draw a line.
Definition: TGX11.cxx:603
Pixmap_t fBackgroundPixmap
Definition: GuiTypes.h:95
void SetWindowBackground(Window_t id, ULong_t color)
Set the window background color.
Definition: GX11Gui.cxx:362
const Mask_t kKeyShiftMask
Definition: GuiTypes.h:196
ULong_t fBackingPixel
Definition: GuiTypes.h:127
const Mask_t kKeyMod1Mask
Definition: GuiTypes.h:199
Bool_t Init(void *display)
Initialize X11 system. Returns kFALSE in case of failure.
Definition: TGX11.cxx:337
Bool_t fHasXft
True when XftFonts are used.
Definition: TGX11.h:152
const Mask_t kButtonMotionMask
Definition: GuiTypes.h:165
void Update(Int_t mode=0)
Flush (mode = 0, default) or synchronize (mode = 1) X output buffer.
Definition: GX11Gui.cxx:2491
Int_t fScreenNumber
Screen number.
Definition: TGX11.h:137
const Mask_t kWACursor
Definition: GuiTypes.h:155
void GetWindowSize(Drawable_t id, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h)
Return geometry of window (should be called GetGeometry but signature already used).
Definition: GX11Gui.cxx:2414
XID Cursor
Definition: TGX11.h:39
Int_t fCount
Definition: GuiTypes.h:184
const Mask_t kGCDashOffset
Definition: GuiTypes.h:307
ULong_t Time_t
Definition: GuiTypes.h:43
#define BIT(n)
Definition: Rtypes.h:120
TH1 * h
Definition: legend2.C:5
static Int_t RootX11ErrorHandler(Display *disp, XErrorEvent *err)
Handle X11 error.
Definition: GX11Gui.cxx:171
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:169
void GrabPointer(Window_t id, UInt_t evmask, Window_t confine, Cursor_t cursor, Bool_t grab=kTRUE, Bool_t owner_events=kTRUE)
Establish an active pointer grab.
Definition: GX11Gui.cxx:1883
EGEventType
Definition: GuiTypes.h:60
Handle_t Cursor_t
Definition: GuiTypes.h:35
const Mask_t kWABackPixmap
Definition: GuiTypes.h:140
const Mask_t kWABorderPixel
Definition: GuiTypes.h:143
const Mask_t kDoRed
Definition: GuiTypes.h:320
Int_t fTsYOrigin
Definition: GuiTypes.h:242
const Mask_t kDoGreen
Definition: GuiTypes.h:321
void UnionRectWithRegion(Rectangle_t *rect, Region_t src, Region_t dest)
Union of rectangle with a region.
Definition: GX11Gui.cxx:2518
const Mask_t kWABitGravity
Definition: GuiTypes.h:145
static const char * filename()
ULong_t * fPixels
Definition: GuiTypes.h:331
#define gROOT
Definition: TROOT.h:340
Int_t fY
Definition: GuiTypes.h:179
Handle_t GContext_t
Definition: GuiTypes.h:39
Colormap_t fColormap
Definition: GuiTypes.h:109
Window_t GetPrimarySelectionOwner()
Returns the window id of the current owner of the primary selection.
Definition: GX11Gui.cxx:2251
void SetClassHints(Window_t id, char *className, char *resourceName)
Set the windows class and resource name.
Definition: GX11Gui.cxx:1951
R__EXTERN Atom_t gWM_DELETE_WINDOW
Definition: TVirtualX.h:51
ULong_t fPlaneMask
Definition: GuiTypes.h:227
void ChangeGC(GContext_t gc, GCValues_t *gval)
Change entries in an existing graphics context, gc, by values from gval.
Definition: GX11Gui.cxx:1007
Basic string class.
Definition: TString.h:137
Bool_t PointInRegion(Int_t x, Int_t y, Region_t reg)
Returns true if the point x,y is in the region.
Definition: GX11Gui.cxx:2580
const Mask_t kGCLineStyle
Definition: GuiTypes.h:292
Int_t EventsPending()
Returns number of pending events.
Definition: GX11Gui.cxx:1414
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
Region_t PolygonRegion(Point_t *points, Int_t np, Bool_t winding)
Create region for the polygon defined by the points array.
Definition: GX11Gui.cxx:2528
const Bool_t kFALSE
Definition: Rtypes.h:92
void RaiseWindow(Window_t id)
Put window on top of window stack.
Definition: GX11Gui.cxx:289
const Mask_t kWABackingStore
Definition: GuiTypes.h:147
Window_t GetDefaultRootWindow() const
Return handle to the default root window created when calling XOpenDisplay().
Definition: GX11Gui.cxx:926
Handle_t Drawable_t
Definition: GuiTypes.h:32
Cursor fCursors[kNumCursors]
List of cursors.
Definition: TGX11.h:91
Int_t fClipYOrigin
Definition: GuiTypes.h:247
Int_t fFillStyle
Definition: GuiTypes.h:235
void SetClipRectangles(GContext_t gc, Int_t x, Int_t y, Rectangle_t *recs, Int_t n)
Set clipping rectangles in graphics context.
Definition: GX11Gui.cxx:2481
void QueryColor(Colormap_t cmap, ColorStruct_t &color)
Fill in the primary color components for a specific pixel value.
Definition: GX11Gui.cxx:1385
Pixmap_t fClipMask
Definition: GuiTypes.h:248
static std::string format(double x, double y, int digits, int width)
ECursor
Definition: TVirtualX.h:56
void MapSubwindows(Window_t id)
Map sub windows.
Definition: GX11Gui.cxx:239
XID Colormap
Definition: TGX11.h:40
Window_t fWindow
Definition: GuiTypes.h:177
Handle_t Display_t
Definition: GuiTypes.h:28
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:592
void ReparentWindow(Window_t id, Window_t pid, Int_t x, Int_t y)
Reparent window to new parent window at position (x,y).
Definition: GX11Gui.cxx:352
void SetCursor(Int_t win, ECursor cursor)
Set the cursor.
Definition: TGX11.cxx:2071
const UInt_t kMaxUInt
Definition: Rtypes.h:102
EGraphicsFunction fFunction
Definition: GuiTypes.h:226
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
Definition: TSystem.cxx:568
const ULong_t kMWMHintsFunctions
Definition: GX11Gui.cxx:55
Bool_t EqualRegion(Region_t rega, Region_t regb)
Returns true if two regions are equal.
Definition: GX11Gui.cxx:2588
void SetWindowName(Window_t id, char *name)
Set window name.
Definition: GX11Gui.cxx:1902
Handle_t FontH_t
Definition: GuiTypes.h:36
Atom_t InternAtom(const char *atom_name, Bool_t only_if_exist)
Return atom handle for atom_name.
Definition: GX11Gui.cxx:914
void DeleteImage(Drawable_t img)
Destroy XImage img.
Definition: GX11Gui.cxx:2676
const Mask_t kWABorderPixmap
Definition: GuiTypes.h:142
ULong_t fBackgroundPixel
Definition: GuiTypes.h:96
const Mask_t kPointerMotionMask
Definition: GuiTypes.h:164
const Mask_t kPAReturnPixels
Definition: GuiTypes.h:342
void GetRegionBox(Region_t reg, Rectangle_t *)
Return smallest enclosing rectangle.
Definition: GX11Gui.cxx:2596
Bool_t fMapInstalled
Definition: GuiTypes.h:130
Int_t OpenDisplay(void *display)
Open the display. Return -1 if the opening fails, 0 when ok.
Definition: TGX11.cxx:1086
UShort_t fRed
Definition: GuiTypes.h:313
#define SafeDelete(p)
Definition: RConfig.h:436
void UnionRegion(Region_t rega, Region_t regb, Region_t result)
Compute the union of rega and regb and return result region.
Definition: GX11Gui.cxx:2538
const Mask_t kGCClipMask
Definition: GuiTypes.h:306
static const double x2[5]
const char * True
Double_t x[n]
Definition: legend1.C:17
unsigned long KeySym
Definition: TGWin32.h:66
void FillPolygon(Window_t id, GContext_t gc, Point_t *points, Int_t npnt)
FillPolygon fills the region closed by the specified path.
Definition: GX11Gui.cxx:2432
Bool_t SetSelectionOwner(Window_t, Atom_t &)
Changes the owner and last-change time for the specified selection.
Definition: GX11Gui.cxx:2752
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
Definition: memory.h:94
void DestroySubwindows(Window_t id)
Destroy subwindows of this window.
Definition: GX11Gui.cxx:279
Drawable fVisRootWin
Root window with fVisual to be used to create GC's and XImages.
Definition: TGX11.h:133
void SetWindowBackgroundPixmap(Window_t id, Pixmap_t pxm)
Set pixmap as window background.
Definition: GX11Gui.cxx:372
Int_t GetProperty(Window_t, Atom_t, Long_t, Long_t, Bool_t, Atom_t, Atom_t *, Int_t *, ULong_t *, ULong_t *, unsigned char **)
Returns the actual type of the property; the actual format of the property; the number of 8-bit...
Definition: GX11Gui.cxx:2716
void ResizeWindow(Int_t wid)
Resize the current window if necessary.
Definition: TGX11.cxx:1914
Region_t CreateRegion()
Create a new empty region.
Definition: GX11Gui.cxx:2502
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition: TROOT.cxx:2469
ULong_t fBackingPlanes
Definition: GuiTypes.h:126
Int_t fDashOffset
Definition: GuiTypes.h:249
Handle_t fHandle
Definition: GuiTypes.h:186
R__EXTERN TFileHandler * gXDisplay
Definition: TSystem.h:550
Handle_t Atom_t
Definition: GuiTypes.h:38
ULong_t fForeground
Definition: GuiTypes.h:228
const Mask_t kPASize
Definition: GuiTypes.h:340
Colormap_t fColormap
Definition: GuiTypes.h:129
const Mask_t kGCFont
Definition: GuiTypes.h:301
void Bell(Int_t percent)
Sound bell. Percent is loudness from -100% .. 100%.
Definition: GX11Gui.cxx:1689
Int_t fXRoot
Definition: GuiTypes.h:180
const Mask_t kGCLineWidth
Definition: GuiTypes.h:291
void DestroyWindow(Window_t id)
Destroy window.
Definition: GX11Gui.cxx:269
void ClearWindow()
Clear current window.
Definition: TGX11.cxx:417
const Mask_t kKeyLockMask
Definition: GuiTypes.h:197
if(pyself &&pyself!=Py_None)
Visual_t GetVisual() const
Returns handle to visual (might be useful in some cases where direct X11 manipulation outside of TVir...
Definition: GX11Gui.cxx:875
const Mask_t kWAColormap
Definition: GuiTypes.h:154
void LookupString(Event_t *event, char *buf, Int_t buflen, UInt_t &keysym)
Convert the keycode from the event structure to a key symbol (according to the modifiers specified in...
Definition: GX11Gui.cxx:2292
const Mask_t kGCGraphicsExposures
Definition: GuiTypes.h:303
Colormap fColormap
Default colormap, 0 if b/w.
Definition: TGX11.h:134
const ULong_t kMWMHintsInputMode
Definition: GX11Gui.cxx:57
void SetKeyAutoRepeat(Bool_t on=kTRUE)
Turn key auto repeat on or off.
Definition: GX11Gui.cxx:1822
Bool_t CreatePictureFromFile(Drawable_t id, const char *filename, Pixmap_t &pict, Pixmap_t &pict_mask, PictureAttributes_t &attr)
Create a picture pixmap from data on file.
Definition: GX11Gui.cxx:1197
void XShapeCombineMask(Display *, Window, int, int, int, Pixmap, int)
void DrawRectangle(Drawable_t id, GContext_t gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw a rectangle outline.
Definition: GX11Gui.cxx:2186
const Mask_t kKeyMod4Mask
Definition: GuiTypes.h:202
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
UInt_t ScreenWidthMM() const
Returns the width of the screen in millimeters.
Definition: GX11Gui.cxx:2695
void SetForeground(GContext_t gc, ULong_t foreground)
Set foreground color in graphics context (shortcut for ChangeGC with only foreground mask set)...
Definition: GX11Gui.cxx:2471
const Mask_t kWABackingPlanes
Definition: GuiTypes.h:148
const Mask_t kGCDashList
Definition: GuiTypes.h:308
void Error(const char *location, const char *msgfmt,...)
void PutPixel(Drawable_t id, Int_t x, Int_t y, ULong_t pixel)
Set pixel at specified location in XImage img.
Definition: GX11Gui.cxx:2656
void IconifyWindow(Window_t id)
Iconify the window.
Definition: GX11Gui.cxx:342
void WMDeleteNotify(Window_t id)
Tell WM to send message when window is closed via WM.
Definition: GX11Gui.cxx:1812
void CopyGC(GContext_t org, GContext_t dest, Mask_t mask)
Copies graphics context from org to dest.
Definition: GX11Gui.cxx:1026
Int_t fTsXOrigin
Definition: GuiTypes.h:241
const ULong_t kMWMHintsDecorations
Definition: GX11Gui.cxx:56
void SubtractRegion(Region_t rega, Region_t regb, Region_t result)
Subtract rega from regb.
Definition: GX11Gui.cxx:2555
Int_t fDepth
Number of color planes.
Definition: TGX11.h:144
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:594
void ConvertSelection(Window_t, Atom_t &, Atom_t &, Atom_t &, Time_t &)
Requests that the specified selection be converted to the specified target type.
Definition: GX11Gui.cxx:2743
#define None
Definition: TGWin32.h:68
point * points
Definition: X3DBuffer.c:20
UShort_t fGreen
Definition: GuiTypes.h:314
const Mask_t kPAColormap
Definition: GuiTypes.h:338
const Mask_t kButtonPressMask
Definition: GuiTypes.h:162
void * fXEvent
Current native (X11) event.
Definition: TGX11.h:92
Bool_t fOverrideRedirect
Definition: GuiTypes.h:108
void SelectInput(Window_t id, UInt_t evmask)
Defines which input events the window is interested in.
Definition: GX11Gui.cxx:2209
const Mask_t kKeyPressMask
Definition: GuiTypes.h:160
const Mask_t kButton3Mask
Definition: GuiTypes.h:206
void QueryPointer(Int_t &ix, Int_t &iy)
Query pointer position.
Definition: TGX11.cxx:1449
void GetWindowAttributes(Window_t id, WindowAttributes_t &attr)
Get window attributes and return filled in attributes structure.
Definition: GX11Gui.cxx:775
Long_t fAllEventMasks
Definition: GuiTypes.h:132
void SetWMSize(Window_t id, UInt_t w, UInt_t h)
Tell the window manager the desired window size.
Definition: GX11Gui.cxx:1999
Bool_t fGraphicsExposures
Definition: GuiTypes.h:245
Int_t fDashLen
Definition: GuiTypes.h:251
Bool_t CheckEvent(Window_t id, EGEventType type, Event_t &ev)
Check if there is for window "id" an event of type "type".
Definition: GX11Gui.cxx:1767
const Int_t kPropMWMHintElements
Definition: GX11Gui.cxx:60
void SetTypeList(Window_t win, Atom_t prop, Atom_t *typelist)
Add the list of drag and drop types to the Window win.
Definition: GX11Gui.cxx:2796
Pixmap_t CreatePixmap(Drawable_t id, UInt_t w, UInt_t h)
Creates a pixmap of the width and height you specified and returns a pixmap ID that identifies it...
Definition: GX11Gui.cxx:1076
EMouseButton
Definition: GuiTypes.h:215
void GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent)
Return some font properties.
Definition: GX11Gui.cxx:2088
ROOT::R::TRInterface & r
Definition: Object.C:4
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
void ChangeActivePointerGrab(Window_t, UInt_t, Cursor_t)
Changes the specified dynamic parameters if the pointer is actively grabbed by the client...
Definition: GX11Gui.cxx:2729
const Mask_t kWAEventMask
Definition: GuiTypes.h:152
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
Long_t fDoNotPropagateMask
Definition: GuiTypes.h:107
const Mask_t kWASaveUnder
Definition: GuiTypes.h:151
Time_t fTime
Definition: GuiTypes.h:178
void UnmapWindow(Window_t id)
Unmap window from screen.
Definition: GX11Gui.cxx:259
EGEventType fType
Definition: GuiTypes.h:176
UInt_t fHeight
Definition: GuiTypes.h:183
const Mask_t kKeyMod5Mask
Definition: GuiTypes.h:203
const Mask_t kGCClipXOrigin
Definition: GuiTypes.h:304
Long_t fDoNotPropagateMask
Definition: GuiTypes.h:134
FontH_t GetFontHandle(FontStruct_t fs)
Return handle to font described by font structure.
Definition: GX11Gui.cxx:964
Handle_t Visual_t
Definition: GuiTypes.h:29
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
Drawable_t CreateImage(UInt_t width, UInt_t height)
Create a client-side XImage. Returns handle to XImage.
Definition: GX11Gui.cxx:2624
void DrawString(Drawable_t id, GContext_t gc, Int_t x, Int_t y, const char *s, Int_t len)
Draw a string using a specific graphics context in position (x,y).
Definition: GX11Gui.cxx:2069
#define ShapeSet
Definition: shapeconst.h:40
const Mask_t kExposureMask
Definition: GuiTypes.h:166
FontStruct_t LoadQueryFont(const char *font_name)
Load font and query font.
Definition: GX11Gui.cxx:955
Display_t GetDisplay() const
Returns handle to display (might be useful in some cases where direct X11 manipulation outside of TVi...
Definition: GX11Gui.cxx:865
void TranslateCoordinates(Window_t src, Window_t dest, Int_t src_x, Int_t src_y, Int_t &dest_x, Int_t &dest_y, Window_t &child)
TranslateCoordinates translates coordinates from the frame of reference of one window to another...
Definition: GX11Gui.cxx:2398
unsigned int UInt_t
Definition: RtypesCore.h:42
void DeleteProperty(Window_t, Atom_t &)
Deletes the specified property only if the property was defined on the specified window and causes th...
Definition: GX11Gui.cxx:2705
const Mask_t kOwnerGrabButtonMask
Definition: GuiTypes.h:171
char * Form(const char *fmt,...)
void DeletePixmap(Pixmap_t pmap)
Explicitly delete pixmap resource.
Definition: GX11Gui.cxx:1106
const Handle_t kNone
Definition: GuiTypes.h:89
Pixmap_t ReadGIF(Int_t x0, Int_t y0, const char *file, Window_t id=0)
If id is NULL - loads the specified gif file at position [x0,y0] in the current window.
Definition: TGX11.cxx:3262
void DrawSegments(Drawable_t id, GContext_t gc, Segment_t *seg, Int_t nseg)
Draws multiple line segments. Each line is specified by a pair of points.
Definition: GX11Gui.cxx:2196
void ShapeCombineMask(Window_t id, Int_t x, Int_t y, Pixmap_t mask)
The Nonrectangular Window Shape Extension adds nonrectangular windows to the System.
Definition: GX11Gui.cxx:2686
void MoveWindow(Int_t wid, Int_t x, Int_t y)
Move the window wid.
Definition: TGX11.cxx:1075
void SetMWMHints(Window_t id, UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition: GX11Gui.cxx:1965
Int_t fYRoot
Definition: GuiTypes.h:180
TLine * l
Definition: textangle.C:4
void NextEvent(Event_t &event)
Copies first pending event from event queue to Event_t structure and removes event from queue...
Definition: GX11Gui.cxx:1425
const Mask_t kGCClipYOrigin
Definition: GuiTypes.h:305
GContext_t CreateGC(Drawable_t id, GCValues_t *gval)
Create a graphics context using the values set in gval (but only for those entries that are in the ma...
Definition: GX11Gui.cxx:985
const Mask_t kGCJoinStyle
Definition: GuiTypes.h:294
void FreeFontStruct(FontStruct_t fs)
Free font structure returned by GetFontStruct().
Definition: GX11Gui.cxx:2134
void ClearArea(Window_t id, Int_t x, Int_t y, UInt_t w, UInt_t h)
Clear a window area to the background color.
Definition: GX11Gui.cxx:1755
void DestroyRegion(Region_t reg)
Destroy region.
Definition: GX11Gui.cxx:2510
#define XA_ATOM
Definition: xatom.h:13
ULong_t fPixel
Definition: GuiTypes.h:312
Window_t FindRWindow(Window_t win, Window_t dragwin, Window_t input, int x, int y, int maxd)
Recursively search in the children of Window for a Window which is at location x, y and is DND aware...
Definition: GX11Gui.cxx:2813
#define gVirtualX
Definition: TVirtualX.h:362
void MoveResizeWindow(Window_t id, Int_t x, Int_t y, UInt_t w, UInt_t h)
Move and resize a window.
Definition: GX11Gui.cxx:319
Pixmap_t fStipple
Definition: GuiTypes.h:240
Handle_t Colormap_t
Definition: GuiTypes.h:34
EKeySym
Definition: KeySymbols.h:27
Pixmap_t CreateBitmap(Drawable_t id, const char *bitmap, UInt_t width, UInt_t height)
Create a bitmap (i.e. pixmap with depth 1) from the bitmap data.
Definition: GX11Gui.cxx:1096
XID Window
Definition: TGX11.h:41
void ChangeWindowAttributes(Window_t id, SetWindowAttributes_t *attr)
Change window attributes.
Definition: GX11Gui.cxx:1712
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:168
long Long_t
Definition: RtypesCore.h:50
ULong_t fBackground
Definition: GuiTypes.h:229
static const double x1[5]
void MapPictureAttributes(PictureAttributes_t &attr, RXpmAttributes &xpmattr, Bool_t toxpm=kTRUE)
Map a PictureAttributes_t to a XpmAttributes structure.
Definition: GX11Gui.cxx:1115
double f(double x)
const Mask_t kGCFillStyle
Definition: GuiTypes.h:295
void MapSetWindowAttributes(SetWindowAttributes_t *attr, ULong_t &xmask, RXSetWindowAttributes &xattr)
Map a SetWindowAttributes_t to a XSetWindowAttributes structure.
Definition: GX11Gui.cxx:479
const Mask_t kStructureNotifyMask
Definition: GuiTypes.h:167
void MapGCValues(GCValues_t &gval, ULong_t &xmask, RXGCValues &xgval, Bool_t tox=kTRUE)
Map a GCValues_t to a XCGValues structure if tox is true.
Definition: GX11Gui.cxx:568
TText * text
#define XA_PRIMARY
Definition: xatom.h:10
void FreeColor(Colormap_t cmap, ULong_t pixel)
Free color cell with specified pixel value.
Definition: GX11Gui.cxx:1405
void FreeFontNames(char **fontlist)
Free list of font names.
Definition: GX11Gui.cxx:2616
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:163
UInt_t fCode
Definition: GuiTypes.h:181
const Handle_t kParentRelative
Definition: GuiTypes.h:91
void GrabButton(Window_t id, EMouseButton button, UInt_t modifier, UInt_t evmask, Window_t confine, Cursor_t cursor, Bool_t grab=kTRUE)
Establish passive grab on a certain mouse button.
Definition: GX11Gui.cxx:1857
Bool_t EmptyRegion(Region_t reg)
Return true if the region is empty.
Definition: GX11Gui.cxx:2572
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
const Mask_t kGCTile
Definition: GuiTypes.h:297
void LowerWindow(Window_t id)
Lower window so it lays below all its siblings.
Definition: GX11Gui.cxx:299
const Mask_t kWAOverrideRedirect
Definition: GuiTypes.h:150
Pixmap_t fBorderPixmap
Definition: GuiTypes.h:97
unsigned long ULong_t
Definition: RtypesCore.h:51
Int_t fJoinStyle
Definition: GuiTypes.h:234
static RooMathCoreReg dummy
Window_t fRoot
Definition: GuiTypes.h:121
Double_t y[n]
Definition: legend1.C:17
void AsmLong(Long_t i1, Long_t i2, Long_t &ll)
Definition: GX11Gui.cxx:159
const Mask_t kGCFunction
Definition: GuiTypes.h:287
Bool_t AllocColor(Colormap cmap, RXColor *color)
Allocate color in colormap.
Definition: TGX11.cxx:361
const Mask_t kPAHotspot
Definition: GuiTypes.h:341
const Mask_t kGCCapStyle
Definition: GuiTypes.h:293
const Mask_t kWAWinGravity
Definition: GuiTypes.h:146
const Mask_t kGCForeground
Definition: GuiTypes.h:289
void SetIconPixmap(Window_t id, Pixmap_t pic)
Set pixmap the WM can use when the window is iconized.
Definition: GX11Gui.cxx:1936
void SetWMSizeHints(Window_t id, UInt_t wmin, UInt_t hmin, UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc)
Give the window manager minimum and maximum size hints.
Definition: GX11Gui.cxx:2016
Int_t fCapStyle
Definition: GuiTypes.h:232
double Time(TStopwatch &w)
Definition: stressTMath.cxx:21
Bool_t CreatePictureFromData(Drawable_t id, char **data, Pixmap_t &pict, Pixmap_t &pict_mask, PictureAttributes_t &attr)
Create a picture pixmap from data.
Definition: GX11Gui.cxx:1250
Long_t fUser[5]
Definition: GuiTypes.h:188
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
void DeleteGC(GContext_t gc)
Explicitly delete a graphics context.
Definition: GX11Gui.cxx:1046
#define name(a, b)
Definition: linkTestLib0.cpp:5
const char * Bool
#define org(otri, vertexptr)
Definition: triangle.c:1037
void XorRegion(Region_t rega, Region_t regb, Region_t result)
Calculate the difference between the union and intersection of two regions.
Definition: GX11Gui.cxx:2564
void MapKeySym(UInt_t &keysym, UInt_t &xkeysym, Bool_t tox=kTRUE)
Map to and from X key symbols.
Definition: GX11Gui.cxx:2314
void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set...
Definition: TException.cxx:27
Mother of all ROOT objects.
Definition: TObject.h:58
ULong_t fBorderPixel
Definition: GuiTypes.h:98
void SetInputFocus(Window_t id)
Set keyboard input focus to window id.
Definition: GX11Gui.cxx:2235
const Mask_t kDoBlue
Definition: GuiTypes.h:322
Int_t fFillRule
Definition: GuiTypes.h:237
R__EXTERN Atom_t gMOTIF_WM_HINTS
Definition: TVirtualX.h:52
const Mask_t kGCStipple
Definition: GuiTypes.h:298
UInt_t fWidth
Definition: GuiTypes.h:183
Bool_t fOverrideRedirect
Definition: GuiTypes.h:135
Handle_t Window_t
Definition: GuiTypes.h:30
Int_t fFormat
Definition: GuiTypes.h:187
Mask_t fMask
Definition: GuiTypes.h:252
UShort_t fMask
Definition: GuiTypes.h:316
const Mask_t kPADepth
Definition: GuiTypes.h:339
#define ShapeBounding
Definition: shapeconst.h:46
void SplitLong(Long_t ll, Long_t &i1, Long_t &i2)
Definition: GX11Gui.cxx:148
void GetImageSize(Drawable_t id, UInt_t &width, UInt_t &height)
Get size of XImage img.
Definition: GX11Gui.cxx:2647
const Mask_t kGCTileStipYOrigin
Definition: GuiTypes.h:300
void IntersectRegion(Region_t rega, Region_t regb, Region_t result)
Compute the intersection of rega and regb and return result region.
Definition: GX11Gui.cxx:2547
void SetPrimarySelectionOwner(Window_t id)
Makes the window id the current owner of the primary selection.
Definition: GX11Gui.cxx:2260
const Mask_t kGCSubwindowMode
Definition: GuiTypes.h:302
void ConvertPrimarySelection(Window_t id, Atom_t clipboard, Time_t when)
XConvertSelection() causes a SelectionRequest event to be sent to the current primary selection owner...
Definition: GX11Gui.cxx:2278
const Mask_t kWABorderWidth
Definition: GuiTypes.h:144
#define dest(otri, vertexptr)
Definition: triangle.c:1040
RVisual * fVisual
Pointer to visual used by all windows.
Definition: TGX11.h:131
#define XA_STRING
Definition: xatom.h:40
void MapWindow(Window_t id)
Map window on screen.
Definition: GX11Gui.cxx:229
Bool_t IsDNDAware(Window_t win, Atom_t *typelist)
Checks if Window win is DND aware, and knows any of the DND formats passed in argument.
Definition: GX11Gui.cxx:2864
const Mask_t kGCBackground
Definition: GuiTypes.h:290
Handle_t Region_t
Definition: GuiTypes.h:33
virtual void MapGCFont(GContext_t, FontStruct_t)
Map the XftFont with the Graphics Context using it.
Definition: TVirtualX.cxx:2503
Colormap_t fColormap
Definition: GuiTypes.h:325
const Mask_t kGCTileStipXOrigin
Definition: GuiTypes.h:299
const Mask_t kFocusChangeMask
Definition: GuiTypes.h:170
Handle_t Pixmap_t
Definition: GuiTypes.h:31
void SetWMState(Window_t id, EInitialState state)
Set the initial state of the window. Either kNormalState or kIconicState.
Definition: GX11Gui.cxx:2038
Int_t fLineWidth
Definition: GuiTypes.h:230
const Int_t kPropMotifWMHintsElements
Definition: GX11Gui.cxx:59
Window_t GetInputFocus()
Returns the window id of the window having the input focus.
Definition: GX11Gui.cxx:2223
void SetWMTransientHint(Window_t id, Window_t main_id)
Tell window manager that window is a transient window of main.
Definition: GX11Gui.cxx:2059
UInt_t fState
Definition: GuiTypes.h:182
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
Bool_t ParseColor(Colormap_t cmap, const char *cname, ColorStruct_t &color)
Parse string cname containing color name, like "green" or "#00FF00".
Definition: GX11Gui.cxx:1345
Drawable fRootWin
Root window used as parent of all windows.
Definition: TGX11.h:132
Int_t KeysymToKeycode(UInt_t keysym)
Convert a keysym to the appropriate keycode.
Definition: GX11Gui.cxx:2165
const Mask_t kWABackPixel
Definition: GuiTypes.h:141
void SetIconName(Window_t id, char *name)
Set window icon name.
Definition: GX11Gui.cxx:1919
Int_t fSubwindowMode
Definition: GuiTypes.h:244
void FillRectangle(Drawable_t id, GContext_t gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw a filled rectangle. Filling is done according to the gc.
Definition: GX11Gui.cxx:2176
double result[121]
const Mask_t kWABackingPixel
Definition: GuiTypes.h:149
const Mask_t kPACloseness
Definition: GuiTypes.h:343
unsigned char UChar_t
Definition: RtypesCore.h:34
const Mask_t kKeyControlMask
Definition: GuiTypes.h:198
Int_t fRedDiv
Red value divider, -1 if no TrueColor visual.
Definition: TGX11.h:145
Cursor_t CreateCursor(ECursor cursor)
Create cursor handle (just return cursor from cursor pool fCursors).
Definition: GX11Gui.cxx:1057
const Mask_t kWADontPropagate
Definition: GuiTypes.h:153
unsigned long Atom
Definition: xatom.h:9
const Bool_t kTRUE
Definition: Rtypes.h:91
const Mask_t kGCArcMode
Definition: GuiTypes.h:309
const Mask_t kAnyModifier
Definition: GuiTypes.h:211
Int_t fArcMode
Definition: GuiTypes.h:238
float value
Definition: math.cpp:443
void CopyArea(Drawable_t src, Drawable_t dest, GContext_t gc, Int_t src_x, Int_t src_y, UInt_t width, UInt_t height, Int_t dest_x, Int_t dest_y)
Copy a drawable (i.e.
Definition: GX11Gui.cxx:1699
Long_t fYourEventMask
Definition: GuiTypes.h:133
Window_t GetParent(Window_t id) const
Return the parent of the window.
Definition: GX11Gui.cxx:934
Int_t TextWidth(FontStruct_t font, const char *s, Int_t len)
Return length of string in pixels. Size depends on font.
Definition: GX11Gui.cxx:2080
ULong_t fBlackPixel
Value of black pixel in colormap.
Definition: TGX11.h:135
const Mask_t kButton1Mask
Definition: GuiTypes.h:204
const Int_t n
Definition: legend1.C:16
Int_t fX
Definition: GuiTypes.h:179
EGraphicsFunction
Definition: GuiTypes.h:68
void ChangeProperties(Window_t id, Atom_t property, Atom_t type, Int_t format, UChar_t *data, Int_t len)
This function alters the property for the specified window and causes the X server to generate a Prop...
Definition: GX11Gui.cxx:2762
void CloseDisplay()
Close connection to display server.
Definition: GX11Gui.cxx:854
void MapEventMask(UInt_t &emask, UInt_t &xemask, Bool_t tox=kTRUE)
Map event mask to or from X.
Definition: GX11Gui.cxx:414
const Mask_t kGCPlaneMask
Definition: GuiTypes.h:288
const char * False
void MapModifierState(UInt_t &state, UInt_t &xstate, Bool_t tox=kTRUE)
Map modifier key state to or from X.
Definition: GX11Gui.cxx:1436
const Mask_t kKeyMod3Mask
Definition: GuiTypes.h:201
ULong_t Handle_t
Definition: GuiTypes.h:27
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904