home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / awm2 / part09 / FocusChng.c next >
Encoding:
C/C++ Source or Header  |  1989-02-20  |  6.1 KB  |  253 lines

  1.  
  2.  
  3.  
  4. #ifndef lint
  5. static char *rcsid_FocusChng_c = "$Header: /usr/graph2/X11.3/contrib/windowmgrs/awm/RCS/FocusChng.c,v 1.2 89/02/07 20:04:50 jkh Exp $";
  6. #endif    lint
  7.  
  8. #include "X11/copyright.h"
  9. /*
  10.  *
  11.  * Copyright 1987, 1988 by Ardent Computer Corporation, Sunnyvale, Ca.
  12.  *
  13.  * Copyright 1987 by Jordan Hubbard.
  14.  *
  15.  *
  16.  *                         All Rights Reserved
  17.  *
  18.  * Permission to use, copy, modify, and distribute this software and its
  19.  * documentation for any purpose and without fee is hereby granted,
  20.  * provided that the above copyright notice appear in all copies and that
  21.  * both that copyright notice and this permission notice appear in
  22.  * supporting documentation, and that the name of Ardent Computer
  23.  * Corporation or Jordan Hubbard not be used in advertising or publicity
  24.  * pertaining to distribution of the software without specific, written
  25.  * prior permission.
  26.  *
  27.  */
  28.  
  29. /*
  30.  * MODIFICATION HISTORY
  31.  *
  32.  * 001 -- Jordan Hubbard, U.C. Berkeley.
  33.  *   Hacks for autoraise and titles.
  34.  * 002 -- Jordan Hubbard, Ardent Computer
  35.  *   Window pixmap changes on focus in/out.
  36.  * 1.4 -- Fixed Focus In/Out handling. Created LightsOn() and LightsOff()
  37.  * to break out the actual process of "highlighting".
  38.  * 1.5 -- Added dynamic installation of colormaps.
  39.  */
  40.  
  41.  
  42. #include "awm.h"
  43.  
  44. #ifdef PCS
  45. #include <bsd/sys/time.h>
  46. #endif /* PCS */
  47. #ifdef titan
  48. #include <sys/time.h>
  49. #endif /* titan */
  50.  
  51. Window FocusWindow;
  52.  
  53. HandleFocusIn(ev)
  54. XEvent *ev;
  55. {
  56.      XEnterWindowEvent *e = (XEnterWindowEvent *)ev;
  57.      Window w = e->window;
  58.      AwmInfoPtr awi;
  59.      XEvent event;
  60.  
  61.      Entry("HandleFocusIn")
  62.  
  63.      if (!(Hilite || Autoraise || InstallColormap) || Snatched)
  64.      Leave(FALSE)
  65.  
  66.      awi = GetAwmInfo(w);
  67.      if (!awi)  /* probably a menu or something */
  68.          Leave(FALSE)
  69.      w = (FrameFocus && awi->frame) ? awi->frame : awi->client;
  70.  
  71.      if (e->detail != NotifyInferior && (e->focus || FrameFocus)) {
  72.       struct timeval foo;
  73.  
  74.       if (e->type != FocusIn) {
  75.            foo.tv_sec = 0;
  76.            foo.tv_usec = RaiseDelay * 1000; 
  77.            /*
  78.         * Sleep for awhile to avoid race conditions and give any
  79.         * potential leave events a chance to get here..
  80.         */
  81.            select(0, 0, 0, 0, &foo);
  82.            /* Did we leave this window already? */
  83.            if (XCheckTypedWindowEvent(dpy, w, LeaveNotify, &event))
  84.             if (event.xcrossing.detail != NotifyInferior)
  85.              Leave(FALSE)
  86.            /*
  87.         * Install a colormap, if necessary.
  88.         */
  89.            if (InstallColormap) {
  90.             XWindowAttributes xwa;
  91.  
  92.             XGetWindowAttributes(dpy, w, &xwa);
  93.             XInstallColormap(dpy, xwa.colormap);
  94.            }
  95.  
  96.            /*
  97.         * If Autoraise is set, raise that puppy..
  98.         */
  99.            if  (Autoraise && (awi->attrs & AT_RAISE))
  100.             XRaiseWindow(dpy, (awi->frame) ? awi->frame : awi->client);
  101.  
  102.            if (!FocusSetByUser && FocusWindow != awi->client &&
  103.            (awi->attrs & AT_INPUT)) {
  104.             if (FrameFocus) {
  105.              XSetInputFocus(dpy, awi->client, RevertToPointerRoot,
  106.                     CurrentTime);
  107.              FocusSetByWM = TRUE;
  108.             }
  109.             FocusWindow = awi->client;
  110.            }
  111.            else
  112.             Leave(FALSE)
  113.       }
  114.       else {
  115.            FocusWindow = awi->client;
  116.            FocusSetByWM = FALSE;
  117.       }
  118.       LightsOn(awi);
  119.      }
  120.      Leave(FALSE)
  121. }
  122.  
  123. HandleFocusOut(ev)
  124. XEvent *ev;
  125. {
  126.      XLeaveWindowEvent *e = (XEnterWindowEvent *)ev;
  127.      Window w = e->window;
  128.      AwmInfoPtr awi;
  129.      XEvent event;
  130.  
  131.      Entry("HandleFocusOut")
  132.  
  133.      awi = GetAwmInfo(w);
  134.      if (!awi) /* probably a menu or something */
  135.          Leave(FALSE)
  136.  
  137.      if (!(Hilite || Autoraise || InstallColormap) || Snatched)
  138.      Leave(FALSE)
  139.  
  140.      w =  (FrameFocus && awi->frame) ? awi->frame : awi->client;
  141.  
  142.      if (e->detail != NotifyInferior && (e->focus || FrameFocus)) {
  143.       if (e->type != FocusOut) {
  144.            /* Did we come back into this window? */
  145.            if (XCheckTypedWindowEvent(dpy, w, EnterNotify, &event)) {
  146.             if (event.xcrossing.detail != NotifyInferior)
  147.              Leave(FALSE)
  148.            }
  149.            if (!FocusSetByUser) {
  150.             if (FrameFocus) {
  151.              XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot,
  152.                     CurrentTime);
  153.              FocusSetByWM = TRUE;
  154.             }
  155.             FocusWindow = RootWindow(dpy, scr);
  156.            }
  157.            else
  158.             Leave(FALSE)
  159.       }
  160.       else {
  161.            FocusWindow = RootWindow(dpy, scr);
  162.            FocusSetByWM = FALSE;
  163.       }
  164.       if (InstallColormap)
  165.            XInstallColormap(dpy, DefaultColormap(dpy, scr));
  166.       LightsOff(awi);
  167.      }
  168.      Leave(FALSE)
  169. }
  170.  
  171. /*
  172.  * Turns higlighting off for a window. Counterpart to LightsOn
  173.  */
  174. LightsOff(awi)
  175. AwmInfoPtr awi;
  176. {
  177.      Entry("LightsOff")
  178.  
  179.      /* set the window border to "gray" stipple */
  180.      if (awi->attrs & AT_INPUT) {
  181. #ifndef RAINBOW
  182.       if (BorderHilite)
  183.            SetBorderPixmaps(awi, GrayPixmap);
  184. #else
  185.       if (BorderHilite)
  186.            SetBorderPixmaps(awi, awi->grayPixmap);
  187. #endif
  188.       if (awi->frame) {
  189.            if (awi->back && awi->title)
  190.             XSetWindowBackgroundPixmap(dpy, awi->title,
  191.                            awi->back);
  192.            if (awi->BC_back && (awi->attrs & AT_BORDER)) {
  193.             XSetWindowBackgroundPixmap(dpy, awi->frame,
  194.                            awi->BC_back);
  195.             XClearWindow(dpy, awi->frame);
  196.            }
  197.            PaintTitle(awi->title, FALSE);
  198.       }
  199.       XSync(dpy, 0);
  200.      }
  201.      Leave(FALSE)
  202. }
  203.  
  204.  
  205. /*
  206.  * Highlight a window. This may involve shuffling pixmaps around
  207.  * and affecting more than just the client window.
  208.  */
  209. LightsOn(awi)
  210. AwmInfoPtr awi;
  211. {
  212.      Entry("LightsOn")
  213.  
  214.      if (awi->attrs & AT_INPUT) {
  215. #ifndef RAINBOW
  216.       if (BorderHilite)
  217.            SetBorderPixmaps(awi, SolidPixmap);
  218. #else
  219.       if (BorderHilite)
  220.            SetBorderPixmaps(awi, awi->solidPixmap);
  221. #endif
  222.       if (awi->frame) {
  223.            if (awi->bold && awi->title) {
  224.             XSetWindowBackgroundPixmap(dpy, awi->title,
  225.                            awi->bold);
  226.             PaintTitle(awi->title, TRUE);
  227.            }
  228.            if (awi->BC_bold && (awi->attrs & AT_BORDER)) {
  229.             XSetWindowBackgroundPixmap(dpy, awi->frame,
  230.                            awi->BC_bold);
  231.             XClearWindow(dpy, awi->frame);
  232.            }
  233.            XSync(dpy, 0);
  234.       }
  235.      }
  236.      Leave(FALSE)
  237. }
  238.  
  239. void SetBorderPixmaps(awi, pix)
  240. AwmInfoPtr awi;
  241. Pixmap pix;
  242. {
  243.      Entry("SetBorderPixmaps")
  244.  
  245.      XSetWindowBorderPixmap(dpy, awi->client, pix);
  246.      if (awi->frame) {
  247.       if (awi->title)
  248.           XSetWindowBorderPixmap(dpy, awi->title, pix);
  249.       XSetWindowBorderPixmap(dpy, awi->frame, pix);
  250.      }
  251.      Leave_void
  252. }
  253.