home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / x386 / x386Cursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-26  |  6.8 KB  |  278 lines

  1. /*
  2.  * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided that
  6.  * the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Thomas Roell not be used in
  9.  * advertising or publicity pertaining to distribution of the software without
  10.  * specific, written prior permission.  Thomas Roell makes no representations
  11.  * about the suitability of this software for any purpose.  It is provided
  12.  * "as is" without express or implied warranty.
  13.  *
  14.  * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16.  * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20.  * PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  * $Header: /proj/X11/mit/server/ddx/x386/RCS/x386Cursor.c,v 1.1 1991/06/02 22:36:09 root Exp $
  23.  */
  24.  
  25. #include "X.h"
  26. #include "Xmd.h"
  27. #include "input.h"
  28. #include "mipointer.h"
  29. #include "scrnintstr.h"
  30.  
  31. #include "compiler.h"
  32.  
  33. #include "x386.h"
  34. #include "x386Procs.h"
  35. #include "atKeynames.h"
  36.  
  37.  
  38. static Bool   x386CursorOffScreen();
  39. static void   x386CrossScreen();
  40. static void   x386WrapCursor();
  41.  
  42. miPointerScreenFuncRec x386PointerScreenFuncs = {
  43.   x386CursorOffScreen,
  44.   x386CrossScreen,
  45.   x386WrapCursor,
  46. };
  47.  
  48.  
  49.  
  50. /*
  51.  * x386InitViewport --
  52.  *      Initialize paning & zooming parameters, so that a driver must only
  53.  *      check what resolutions are possible and whether the virtual area
  54.  *      is valid if specifyed.
  55.  */
  56.  
  57. void
  58. x386InitViewport(pScr)
  59.      ScrnInfoPtr pScr;
  60. {
  61.   DisplayModePtr pMode, pEnd;
  62.   int            virtualX, virtualY;
  63.  
  64.   /*
  65.    * look for the greatest resolutions and take the dimensions as
  66.    * virtual area
  67.    */
  68.   virtualX = virtualY = -1;
  69.   
  70.   pMode = pEnd = pScr->modes;
  71.   do {
  72.     virtualX = max( pMode->HDisplay, virtualX);
  73.     virtualY = max( pMode->VDisplay, virtualY);
  74.     pMode = pMode->next;
  75.   }
  76.   while (pMode != pEnd);
  77.  
  78.   if (pScr->virtualX < virtualX || pScr->virtualY < virtualY)
  79.     {
  80.       pScr->virtualX = virtualX;
  81.       pScr->virtualY = virtualY;
  82.     }
  83.  
  84.   /*
  85.    * Compute the initial Viewport if necessary
  86.    */
  87.   if (pScr->frameX0 < 0)
  88.     {
  89.       pScr->frameX0 = (pScr->virtualX - pScr->modes->HDisplay) / 2;
  90.       pScr->frameY0 = (pScr->virtualY - pScr->modes->VDisplay) / 2;
  91.     }
  92.   pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
  93.   pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
  94.  
  95.   /*
  96.    * Now adjust the initial Viewport, so it lies within the virtual area
  97.    */
  98.   if (pScr->frameX1 >= pScr->virtualX)
  99.     {
  100.     pScr->frameX0 = pScr->virtualX - pScr->modes->HDisplay;
  101.     pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
  102.     }
  103.  
  104.   if (pScr->frameY1 >= pScr->virtualY)
  105.     {
  106.     pScr->frameY0 = pScr->virtualY - pScr->modes->VDisplay;
  107.     pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
  108.     }
  109. }
  110.  
  111.  
  112. /*
  113.  * x386SetViewport --
  114.  *      Scroll the visual part of the screen so the pointer is visible.
  115.  */
  116.  
  117. void
  118. x386SetViewport(pScreen, x, y)
  119.      ScreenPtr   pScreen;
  120.      int         x, y;
  121. {
  122.   Bool          frameChanged = FALSE;
  123.   ScrnInfoPtr   pScr = X386SCRNINFO(pScreen);
  124.  
  125.   /*
  126.    * check wether (x,y) belongs to the visual part of the screen
  127.    * if not, change the base of the displayed frame accoring
  128.    */
  129.   if ( pScr->frameX0 > x) { 
  130.     pScr->frameX0 = x;
  131.     pScr->frameX1 = x + pScr->modes->HDisplay - 1;
  132.     frameChanged = TRUE ;
  133.   }
  134.   
  135.   if ( pScr->frameX1 < x) { 
  136.     pScr->frameX1 = x + 1;
  137.     pScr->frameX0 = x - pScr->modes->HDisplay + 2;
  138.     frameChanged = TRUE ;
  139.   }
  140.   
  141.   if ( pScr->frameY0 > y) { 
  142.     pScr->frameY0 = y;
  143.     pScr->frameY1 = y + pScr->modes->VDisplay - 1;
  144.     frameChanged = TRUE;
  145.   }
  146.   
  147.   if ( pScr->frameY1 < y) { 
  148.     pScr->frameY1 = y;
  149.     pScr->frameY0 = y - pScr->modes->VDisplay + 1;
  150.     frameChanged = TRUE; 
  151.   }
  152.   
  153.   if (frameChanged) (pScr->AdjustFrame)(pScr->frameX0, pScr->frameY0);
  154. }
  155.  
  156.  
  157.  
  158. /*
  159.  * x386ZoomViewport --
  160.  *      Reinitialize the visual part of the screen for another modes->
  161.  */
  162.  
  163. void
  164. x386ZoomViewport (pScreen, zoom)
  165.      ScreenPtr   pScreen;
  166.      int        zoom;
  167. {
  168.   int           x, y;
  169.   ScrnInfoPtr   pScr = X386SCRNINFO(pScreen);
  170.  
  171.   if (pScr->modes != pScr->modes->next)
  172.     {
  173.       pScr->modes = zoom > 0 ? pScr->modes->next : pScr->modes->prev;
  174.  
  175.       (pScr->SwitchMode)(pScr->modes);
  176.  
  177.       /* 
  178.        * adjust new frame for the displaysize
  179.        */
  180.       pScr->frameX0 = (pScr->frameX1 + pScr->frameX0 -pScr->modes->HDisplay)/2;
  181.       pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
  182.  
  183.       if (pScr->frameX0 < 0)
  184.     {
  185.       pScr->frameX0 = 0;
  186.       pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
  187.     }
  188.       else if (pScr->frameX1 >= pScr->virtualX)
  189.     {
  190.       pScr->frameX0 = pScr->virtualX - pScr->modes->HDisplay;
  191.       pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
  192.     }
  193.       
  194.       pScr->frameY0 = (pScr->frameY1 + pScr->frameY0 -pScr->modes->VDisplay)/2;
  195.       pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
  196.  
  197.       if (pScr->frameY0 < 0)
  198.     {
  199.       pScr->frameY0 = 0;
  200.       pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
  201.     }
  202.       else if (pScr->frameY1 >= pScr->virtualY)
  203.     {
  204.       pScr->frameY0 = pScr->virtualY - pScr->modes->VDisplay;
  205.       pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
  206.     }
  207.     }
  208.  
  209.   (pScr->AdjustFrame)(pScr->frameX0, pScr->frameY0);
  210. }
  211.  
  212.  
  213.  
  214. /*
  215.  * x386CursorOffScreen --
  216.  *      Check whether it is necessary to switch to another screen
  217.  */
  218.  
  219. /* ARGSUSED */
  220. static Bool
  221. x386CursorOffScreen (pScreen, x, y)
  222.      ScreenPtr   *pScreen;
  223.      int         *x, *y;
  224. {
  225.   int        i;
  226.  
  227.   if ((screenInfo.numScreens > 1) && ((*x < 0) || ((*pScreen)->width <= *x))) {
  228.     i = (*pScreen)->myNum;
  229.     if (*x < 0) {
  230.       i = (i ? i : screenInfo.numScreens) -1;
  231.       *pScreen = screenInfo.screens[i];
  232.       *x += (*pScreen)->width;
  233.     }
  234.     else {
  235.       *x -= (*pScreen)->width;
  236.       i = (i+1) % screenInfo.numScreens;
  237.       *pScreen = screenInfo.screens[i];
  238.     }
  239.     return(TRUE);
  240.   }
  241.   return(FALSE);
  242. }
  243.  
  244.  
  245.  
  246. /*
  247.  * x386CrossScreen --
  248.  *      Switch to another screen
  249.  */
  250.  
  251. /* ARGSUSED */
  252. static void
  253. x386CrossScreen (pScreen, entering)
  254.      ScreenPtr   pScreen;
  255.      Bool        entering;
  256. {
  257.   if (x386Info.sharedMonitor)
  258.     (X386SCRNINFO(pScreen)->EnterLeaveMonitor)(entering);
  259.   (X386SCRNINFO(pScreen)->EnterLeaveCursor)(entering);
  260. }
  261.  
  262.  
  263. /*
  264.  * x386WrapCursor --
  265.  *      Wrap possible to another screen
  266.  */
  267.  
  268. /* ARGSUSED */
  269. static void
  270. x386WrapCursor (pScreen, x, y)
  271.      ScreenPtr   pScreen;
  272.      int         x,y;
  273. {
  274.   miPointerWarpCursor(pScreen,x,y);
  275.  
  276.   x386Info.currentScreen = pScreen;
  277. }
  278.