home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / ibm / common / ibmSave.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  9.5 KB  |  372 lines

  1. /*
  2.  * $XConsortium: ibmSave.c,v 1.2 91/07/16 13:09:55 jap Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989,1990,1991
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * License to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND 
  18.  * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
  19.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23.  * SOFTWARE.
  24.  *
  25. */
  26.  
  27. #define NEED_EVENTS
  28.  
  29. #include "X.h"
  30. #define NEED_REPLIES
  31. #include "Xproto.h"
  32. #include "misc.h"
  33. #include "scrnintstr.h"
  34. #include "os.h"
  35. #include "regionstr.h"
  36. #include "windowstr.h"
  37. #include "input.h"
  38. #include "resource.h"
  39. #include "colormapst.h"
  40. #include "cursorstr.h"
  41. #include "dixstruct.h"
  42. #include "gc.h"
  43. #include "gcstruct.h"
  44. #include "servermd.h"
  45. #include "miscstruct.h"
  46. #include "pixmapstr.h"
  47. #include "colormap.h"
  48.  
  49. #include "compiler.h"
  50.  
  51. #include "ibmKeybd.h"
  52. #include "ibmMouse.h"
  53.  
  54. #include "ibmScreen.h"
  55. #include "OSio.h"
  56. #include "ibmTrace.h"
  57.  
  58. #include <stdio.h>
  59.  
  60. extern WindowPtr *WindowTable;
  61.  
  62. /***====================================================================***/
  63.  
  64. static    WindowPtr obscuringWins[MAXSCREENS];
  65. extern    int    ScreenSaverTime,ScreenSaverInterval;
  66. static    int    realSaverTime;
  67. static    int    realSaverInterval;
  68.     int    ibmRefreshOnActivate= TRUE ;
  69.  
  70. /***====================================================================***/
  71.  
  72. void
  73. ibmObscureScreen(pScreen)
  74. ScreenPtr    pScreen;
  75. {
  76. WindowPtr    pWin;
  77. unsigned    mask= CWBackPixel;
  78. XID        attributes[2];
  79. int        result;
  80.  
  81.     TRACE(("ibmObscureScreen()\n"));
  82.     attributes[0]= pScreen->blackPixel;
  83.     obscuringWins[pScreen->myNum]= CreateWindow(
  84.             FakeClientID(0),        /* window id */
  85.             WindowTable[pScreen->myNum],    /* parent */
  86.             0,0,                /* x,y */
  87.             pScreen->width,pScreen->height,    /* width,height */
  88.             0,                /* border width */
  89.             InputOutput,            /* class */
  90.             mask, attributes,        /* attributes */
  91.             0,                /* depth */
  92.             (ClientPtr)NULL,        /* client */
  93.             WindowTable[pScreen->myNum]->optional->visual,
  94.                             /* visual */
  95.             &result);            /* error */
  96.  
  97.     pWin = obscuringWins[pScreen->myNum] ;
  98.     TRACE(("PWIN is %x\n",pWin));
  99.     TRACE(("PWINID is %x\n",pWin->drawable.id));
  100.  
  101.     AddResource(pWin->drawable.id,RT_WINDOW,(pointer)pWin);
  102.     pWin->overrideRedirect= TRUE;
  103.     TRACE(("before Map is \n",pWin));
  104.     MapWindow( pWin, TRUE, FALSE, FALSE, (ClientPtr)NULL);
  105.  
  106.     return;
  107. }
  108.  
  109. /***====================================================================***/
  110.  
  111. void
  112. ibmExposeScreen(pScreen)
  113. ScreenPtr    pScreen;
  114. {
  115. WindowPtr    pWin= obscuringWins[pScreen->myNum];
  116.  
  117.     TRACE(("ibmExposeScreen(0x%x)\n",pScreen));
  118.     FreeResource(pWin->drawable.id,RC_VANILLA);
  119.     obscuringWins[pScreen->myNum]= NULL;
  120.     return;
  121. }
  122.  
  123. /***====================================================================***/
  124.  
  125. static    PixmapPtr saveMaps[MAXSCREENS] = {(PixmapPtr) 0, (PixmapPtr) 0};
  126.    /* must be zero initially */
  127.  
  128. PixmapPtr
  129. ibmSaveScreenData(pScreen,pSaveFunc)
  130. ScreenPtr    pScreen;
  131. void        (*pSaveFunc)();
  132. {
  133. RegionPtr    pRgn;
  134. PixmapPtr    pPix;
  135.  
  136.     TRACE(("ibmSaveScreenData(0x%x)\n",pScreen));
  137.     pRgn = &(WindowTable[pScreen->myNum]->winSize);
  138.  
  139.     if (!saveMaps[pScreen->myNum])
  140.      saveMaps[pScreen->myNum] = (*pScreen->CreatePixmap)(pScreen,
  141.                         REGION_RECTS(pRgn)->x2,
  142.                         REGION_RECTS(pRgn)->y2,
  143.                         pScreen->rootDepth);
  144.     pPix = saveMaps[pScreen->myNum] ;
  145.     (*pSaveFunc)(pPix,pRgn,0,0);
  146.     return(pPix);
  147. }
  148.  
  149. /***====================================================================***/
  150.  
  151. void
  152. ibmRestoreScreenData(pScreen,pRestoreFunc)
  153. ScreenPtr    pScreen;
  154. void        (*pRestoreFunc)();
  155. {
  156. RegionPtr    pRgn;
  157.  
  158.     TRACE(("ibmRestoreScreenData(0x%x)\n",pScreen));
  159.     pRgn= &(WindowTable[pScreen->myNum]->winSize);
  160.     (*pRestoreFunc)(saveMaps[pScreen->myNum],pRgn,0,0);
  161.     return;
  162. }
  163.  
  164. /***====================================================================***/
  165.  
  166. #ifdef AIXV3
  167. /*
  168.  
  169. Hotkey Away:
  170.     1) when we get a retract, call "ibmDeactivateScreens()"
  171.     2) if this is the first retract (to check use: "if( IAmListening ){"),
  172.         call a function to turn off direct window access. Also call
  173.         "DontListenToAnybody()" and set "IAmListening" to FALSE.
  174.     3) find out which screen is getting the retract (with the function
  175.         "WhoIsGettingTheRetract()" and call the save function for
  176.         that screen.
  177.  
  178. Hotkey Back:
  179.     1) when we get a grant, it will be on the virtual terminal that
  180.         we use for input.
  181.     2) go through the list of screens and make sure the virtual terminal
  182.         is active.  If it is not active call
  183.         "hftActivateVT(ibmScreenFD(scrn))"  and wait for a grant.
  184.         (I'm not sure we will get the grants on all the virtual
  185.         terminals)
  186.     3) go through the list of screens again and call the restore function
  187.         for that screen only if the screen is inactive.
  188.     4) call "PayAttentionToClientsAgain()" to wake up the clients.
  189.     5) call a function to turn on direct window access.
  190.  
  191. */
  192. #else AIXV3
  193. #endif /* AIXV3 */
  194.  
  195. #ifdef AIXV3
  196. /* file descriptor to send the Release to after a Retract has been received */
  197. int  RetractFD;
  198. int  IAmListening = TRUE;
  199.  
  200. void
  201. TurnOffDirectWindowAccess()
  202. {
  203. }
  204.  
  205. void
  206. TurnOnDirectWindowAccess()
  207. {
  208. }
  209.  
  210.  
  211. void
  212. ibmDeactivateScreens()
  213. {
  214. ScreenPtr     pScreen;
  215. void         (*fnp)();
  216. int        scrn;
  217.     unsigned  devid;
  218.  
  219.     TRACE(("ibmDeactivateScreens()\n"));
  220. #ifdef OS_SaveState
  221.     OS_SaveState();
  222. #endif
  223.  
  224.     if( IAmListening ){
  225.     TurnOffDirectWindowAccess();
  226.     DontListenToAnybody();
  227.     IAmListening = FALSE;
  228.     }
  229.  
  230.     devid = WhoIsGettingTheRetract();
  231.  
  232.     for (scrn = 0; scrn < ibmNumScreens; scrn++) {
  233.       if( devid == ibmDeviceID(scrn) ){
  234.     pScreen = ibmScreen(scrn);
  235.     RetractFD = ibmScreenFD(scrn);
  236.     TRACE(("ibmDeactivateScreens() scrn=%d  pScreen->myNum=%d\n",scrn,pScreen->myNum));
  237.     if ((!pScreen)||(ibmScreenState(pScreen->myNum)!=SCREEN_ACTIVE)){
  238.         TRACE(("ibmDeactivateScreens() screen %d not active, not saving\n",scrn));
  239.         break;;
  240.     }
  241.     if (!pScreen) {
  242.         ErrorF("Trying to deactivate null screen\n");
  243.         return ;
  244.     }
  245.     
  246.     if (ibmRefreshOnActivate)    ibmObscureScreen(pScreen);
  247.  
  248.     /* find out what the screen wants to do vis-a-vis saving */
  249.     fnp = ibmScreens[scrn]->ibm_SaveFunc;
  250.     if (fnp) {
  251.         TRACE(("ibmDeactivateScreens() before calling save func for %d\n",scrn));
  252.         (*fnp)(pScreen,!ibmRefreshOnActivate);
  253.         TRACE(("ibmDeactivateScreens() after calling save func for %d\n",scrn));
  254.     }
  255.     else{
  256.         TRACE(("ibmDeactivateScreens() screen %d doesn't have a save function\n",scrn));
  257.     }
  258.     ibmSetScreenState(pScreen->myNum,SCREEN_INACTIVE);
  259.     break;
  260.       }
  261.     }
  262.  
  263.     return;
  264. }
  265.  
  266. #else AIXV3
  267.  
  268. void
  269. ibmDeactivateScreens()
  270. {
  271. ScreenPtr     pScreen;
  272. void         (*fnp)();
  273. int        scrn;
  274.  
  275.     TRACE(("ibmDeactivateScreens()\n"));
  276. #ifdef OS_SaveState
  277.     OS_SaveState();
  278. #endif
  279.  
  280.     for (scrn = 0; scrn < ibmNumScreens; scrn++) {
  281.  
  282.     pScreen = ibmScreen(scrn);
  283.     TRACE(("ibmDeactivateScreens() scrn=%d  pScreen->myNum=%d\n",scrn,pScreen->myNum));
  284.     if ((!pScreen)||(ibmScreenState(pScreen->myNum)!=SCREEN_ACTIVE)){
  285.         TRACE(("ibmDeactivateScreens() screen %d not active, not saving\n",scrn));
  286.         continue;
  287.     }
  288.     if (!pScreen) {
  289.         ErrorF("Trying to deactivate null screen\n");
  290.         return ;
  291.     }
  292.     
  293.     if (ibmRefreshOnActivate)    ibmObscureScreen(pScreen);
  294.  
  295.     /* find out what the screen wants to do vis-a-vis saving */
  296.     fnp = ibmScreens[scrn]->ibm_SaveFunc;
  297.     if (fnp) {
  298.         TRACE(("ibmDeactivateScreens() before calling save func for %d\n",scrn));
  299.         (*fnp)(pScreen,!ibmRefreshOnActivate);
  300.         TRACE(("ibmDeactivateScreens() after calling save func for %d\n",scrn));
  301.     }
  302.     else{
  303.         TRACE(("ibmDeactivateScreens() screen %d doesn't have a save function\n",scrn));
  304.     }
  305.     ibmSetScreenState(pScreen->myNum,SCREEN_INACTIVE);
  306.     }
  307.     DontListenToAnybody();
  308.     return;
  309. }
  310. #endif AIXV3
  311.     
  312. void
  313. ibmReactivateScreens()
  314. {
  315. ScreenPtr     pScreen;
  316. void         (*fnp)();
  317. int        scrn;
  318. WindowPtr    pRoot;
  319. ColormapPtr    pCmap;
  320.  
  321.  
  322.     TRACE(("ibmReactivateScreens()\n"));
  323.  
  324. #ifdef OS_RestoreState
  325.     OS_RestoreState();
  326. #endif
  327.  
  328.     PayAttentionToClientsAgain();
  329.  
  330. #ifdef AIXV3
  331.  
  332.     IAmListening = TRUE;
  333.  
  334.  
  335.     for (scrn = 0; scrn < ibmNumScreens; scrn++) {
  336.     hftActivateVT(ibmScreenFD(scrn));
  337.     /* wait for grant here if we need to */
  338.     }
  339.  
  340. #endif /* AIXV3 */
  341.  
  342.  
  343.     for (scrn = 0; scrn < ibmNumScreens; scrn++) {
  344.     pScreen = ibmScreen(scrn);
  345.     TRACE(("ibmReactivateScreens() scrn=%d  pScreen->myNum=%d\n",scrn,pScreen->myNum));
  346.  
  347.     if ((!pScreen)||(ibmScreenState(pScreen->myNum)!=SCREEN_INACTIVE)){
  348.         TRACE(("ibmReactivateScreens() screen %d is not inactive, not restoring\n",scrn));
  349.         continue;
  350.     }
  351.         
  352.     ibmSetScreenState(pScreen->myNum,SCREEN_ACTIVE);
  353.  
  354.     fnp = ibmScreens[scrn]->ibm_RestoreFunc;
  355.     if (fnp){
  356.         TRACE(("ibmReactivateScreens() before calling restore func for screen %d\n",scrn));
  357.         (*fnp)(pScreen,!ibmRefreshOnActivate);
  358.         TRACE(("ibmReactivateScreens() after calling restore func for screen %d\n",scrn));
  359.     }
  360.     else{
  361.         TRACE(("ibmReactivateScreens() screen %d does not have a restore function\n",scrn));
  362.     }
  363.     if (ibmRefreshOnActivate)    ibmExposeScreen(pScreen);
  364.     }
  365.  
  366. #ifdef AIXV3
  367.     TurnOnDirectWindowAccess();
  368. #endif /* AIXV3 */
  369.  
  370.     return;
  371. }
  372.