XWorkstation.st
changeset 18 9ffa3bf0ee58
parent 12 9f0995fac1fa
child 21 7b3da079729d
equal deleted inserted replaced
17:be9898c59977 18:9ffa3bf0ee58
    34 COPYRIGHT (c) 1989 by Claus Gittinger
    34 COPYRIGHT (c) 1989 by Claus Gittinger
    35               All Rights Reserved
    35               All Rights Reserved
    36 
    36 
    37 this class provides the interface to X11
    37 this class provides the interface to X11
    38 
    38 
    39 $Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.6 1993-12-11 01:35:51 claus Exp $
    39 $Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.7 1993-12-16 10:59:26 claus Exp $
    40 written spring/summer 89 by claus
    40 written spring/summer 89 by claus
    41 '!
    41 '!
    42 
    42 
    43 %{
    43 %{
    44 /* x does a typedef Time - I need Object Time ... */
    44 /* x does a typedef Time - I need Object Time ... */
    96  */
    96  */
    97 static char lastErrorMsg[80] = "";
    97 static char lastErrorMsg[80] = "";
    98 static unsigned lastRequestCode = 0;
    98 static unsigned lastRequestCode = 0;
    99 static unsigned lastMinorCode = 0;
    99 static unsigned lastMinorCode = 0;
   100 static unsigned lastResource = 0;
   100 static unsigned lastResource = 0;
       
   101 /*
       
   102  * trying to catch some persitant X-errors
       
   103  */
       
   104 #ifdef DEBUG
       
   105 static unsigned lastColor = 0;
       
   106 #endif
   101 
   107 
   102 __XErrorHandler__(dpy, event)
   108 __XErrorHandler__(dpy, event)
   103     Display *dpy;
   109     Display *dpy;
   104     XErrorEvent *event;
   110     XErrorEvent *event;
   105 {
   111 {
   112     lastResource = event->resourceid;
   118     lastResource = event->resourceid;
   113 
   119 
   114     printf("x-error (%s) cought maj=%d (0x%x) min=%d (0x%x) resource=%x\n",
   120     printf("x-error (%s) cought maj=%d (0x%x) min=%d (0x%x) resource=%x\n",
   115            lastErrorMsg, event->request_code, event->request_code, 
   121            lastErrorMsg, event->request_code, event->request_code, 
   116            event->minor_code, event->minor_code, event->resourceid);
   122            event->minor_code, event->minor_code, event->resourceid);
       
   123 #ifdef DEBUG
       
   124     switch(event->request_code) {
       
   125 	case 88:
       
   126 	    printf("lastColor = %d\n", lastColor);
       
   127 	    break;
       
   128     }
       
   129 #endif
   117     errorInterrupt();
   130     errorInterrupt();
   118     return 0;
   131     return 0;
       
   132 }
       
   133 
       
   134 /*
       
   135  * added since RootWindow-macro is not suficient
       
   136  * when virtual root-windows are involved (i.e. tvtwm)
       
   137  */
       
   138 static Window
       
   139 getRootWindow(dpy, screen)
       
   140     Display *dpy;
       
   141 {
       
   142     Window root;
       
   143     Atom vRootAtom = None;
       
   144     int i;
       
   145     Window rootReturn, parentReturn;
       
   146     Window* children;
       
   147     unsigned int numChildren;
       
   148 
       
   149     root = RootWindow(dpy, screen);
       
   150     /*
       
   151      * on IRIS, this creates a badwindow error - why ?
       
   152      * children contains a funny window (000034)
       
   153      */
       
   154 #ifndef IRIS
       
   155     if (XQueryTree(dpy, root, &rootReturn, &parentReturn, &children, &numChildren)) {
       
   156         vRootAtom = XInternAtom(dpy, "__SWM_VROOT", True );
       
   157         if (vRootAtom != None) {
       
   158             for (i=0; i < numChildren; i++) {
       
   159                 Atom actual_type;
       
   160                 int actual_format;
       
   161                 unsigned long nitems, bytesafter;
       
   162                 Window* newRoot = (Window*) 0;
       
   163 
       
   164                 if (children[i]) {
       
   165                     if (XGetWindowProperty(dpy, children[i], vRootAtom,
       
   166                                            0L, 1L, False, XA_WINDOW,
       
   167                                            &actual_type, &actual_format, &nitems, &bytesafter,
       
   168                                            (unsigned char**) &newRoot) == Success && newRoot) {
       
   169                         root = *newRoot;
       
   170                         break;
       
   171                     }
       
   172                 }
       
   173             }
       
   174             if (children) XFree( children );
       
   175         }
       
   176     }
       
   177 #endif
       
   178     return root;
   119 }
   179 }
   120 
   180 
   121 /*
   181 /*
   122  * some defines - tired of typing ...
   182  * some defines - tired of typing ...
   123  */
   183  */
   623 
   683 
   624     x1 := aPoint x.
   684     x1 := aPoint x.
   625     y1 := aPoint y.
   685     y1 := aPoint y.
   626 %{
   686 %{
   627     int xpos, ypos;
   687     int xpos, ypos;
   628     Window child_return;
   688     Window w1, w2, child_return;
       
   689     int screen = _intVal(_INST(screen));
       
   690     Display *dpy = myDpy;
   629 
   691 
   630     if (_isSmallInteger(windowId1) && _isSmallInteger(windowId2)
   692     if (_isSmallInteger(windowId1) && _isSmallInteger(windowId2)
   631      && _isSmallInteger(x1) && _isSmallInteger(y1)) {
   693      && _isSmallInteger(x1) && _isSmallInteger(y1)) {
   632         XTranslateCoordinates(myDpy, _WindowVal(windowId1), _WindowVal(windowId2),
   694 	w1 = _WindowVal(windowId1);
       
   695 	w2 = _WindowVal(windowId2);
       
   696 #ifndef IRIS
       
   697 	if ((w1 == RootWindow(dpy, screen))
       
   698 	 || (w2 == RootWindow(dpy, screen))) {
       
   699 	    if (w1 == RootWindow(dpy, screen)) {
       
   700 		w1 = getRootWindow(dpy, screen);
       
   701 	    }
       
   702 	    if (w2 == RootWindow(dpy, screen)) {
       
   703 		w2 = getRootWindow(dpy, screen);
       
   704 	    }
       
   705 	}
       
   706 #endif
       
   707         XTranslateCoordinates(dpy, w1, w2,
   633                               _intVal(x1), _intVal(y1), 
   708                               _intVal(x1), _intVal(y1), 
   634                               &xpos, &ypos, &child_return);
   709                               &xpos, &ypos, &child_return);
   635         x2 = _MKSMALLINT(xpos);
   710         x2 = _MKSMALLINT(xpos);
   636         y2 = _MKSMALLINT(ypos);
   711         y2 = _MKSMALLINT(ypos);
   637     }
   712     }
  1967         int screen = _intVal(_INST(screen));
  2042         int screen = _intVal(_INST(screen));
  1968         Window rootRet, childRet;
  2043         Window rootRet, childRet;
  1969         int rootX, rootY, winX, winY;
  2044         int rootX, rootY, winX, winY;
  1970         unsigned int mask;
  2045         unsigned int mask;
  1971 
  2046 
       
  2047 #ifdef OLD
  1972         w = RootWindow(dpy, screen);
  2048         w = RootWindow(dpy, screen);
       
  2049 #else
       
  2050 	w = getRootWindow(myDpy, screen);
       
  2051 #endif
  1973         XQueryPointer(dpy, w, &rootRet, &childRet,
  2052         XQueryPointer(dpy, w, &rootRet, &childRet,
  1974                               &rootX, &rootY,
  2053                               &rootX, &rootY,
  1975                               &winX, &winY,
  2054                               &winX, &winY,
  1976                               &mask);
  2055                               &mask);
  1977         xpos = _MKSMALLINT(rootX);
  2056         xpos = _MKSMALLINT(rootX);
  2024     unsigned long color;
  2103     unsigned long color;
  2025     int screen = _intVal(_INST(screen));
  2104     int screen = _intVal(_INST(screen));
  2026 
  2105 
  2027     if (_isSmallInteger(colorIndex)) {
  2106     if (_isSmallInteger(colorIndex)) {
  2028         color = (long) _intVal(colorIndex);
  2107         color = (long) _intVal(colorIndex);
       
  2108 #ifdef DEBUG
       
  2109 	lastColor = color;
       
  2110 #endif
  2029         XFreeColors(dpy, DefaultColormap(dpy, screen), &color, 1, 0L);
  2111         XFreeColors(dpy, DefaultColormap(dpy, screen), &color, 1, 0L);
  2030         RETURN ( self );
  2112         RETURN ( self );
  2031     }
  2113     }
  2032 %}
  2114 %}
  2033 .
  2115 .