Advertisement
Guest User

compiz

a guest
Jan 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.53 KB | None | 0 0
  1. case FocusIn:
  2.     {
  3.     if (!XGetWindowAttributes (privateScreen.dpy, event->xfocus.window, &wa))
  4.         privateScreen.setDefaultWindowAttributes (&wa);
  5.  
  6.         /* If the call to XGetWindowAttributes failed it means
  7.          * the window was destroyed, so track the focus change
  8.          * anyways since we need to increment activeNum
  9.          * and the passive button grabs and then we will
  10.          * get the DestroyNotify later and change the focus
  11.          * there
  12.      */
  13.  
  14.     if (wa.root == privateScreen.rootWindow())
  15.     {
  16.         if (event->xfocus.mode == NotifyGrab)
  17.         privateScreen.eventManager.grabNotified ();
  18.         else if (event->xfocus.mode == NotifyUngrab)
  19.         privateScreen.eventManager.ungrabNotified ();
  20.         else
  21.         {
  22.         CompWindowList dockWindows;
  23.         XWindowChanges xwc;
  24.         unsigned int   mask;
  25.  
  26.         w = findTopLevelWindow (event->xfocus.window);
  27.         if (w && w->managed ())
  28.         {
  29.             unsigned int state = w->state ();
  30.  
  31.             if (getNextActiveWindow() == event->xfocus.window)
  32.             setNextActiveWindow(None);
  33.  
  34.             if (w->id () != privateScreen.orphanData.activeWindow)
  35.             {
  36.             CompWindow     *active = screen->findWindow (privateScreen.orphanData.activeWindow);
  37.  
  38.             privateScreen.orphanData.activeWindow = w->id ();
  39.             w->priv->activeNum = nextActiveNum();
  40.  
  41.             if (active)
  42.             {
  43.                 CompWindowList windowsLostFocus;
  44.                 /* If this window lost focus and was above a fullscreen window
  45.                  * and is no longer capable of being focused (eg, it is
  46.                  * not visible on this viewport) then we need to check if
  47.                  * any other windows below it are also now no longer capable
  48.                  * of being focused and restack them in the highest position
  49.                  * below docks that they are allowed to take */
  50.                 if (!active->focus ())
  51.                 {
  52.                 windowsLostFocus.push_back (active);
  53.                 for (CompWindow *fsw = active->prev; fsw; fsw = fsw->prev)
  54.                 {
  55.                     if (!fsw->focus () &&
  56.                     fsw->managed () &&
  57.                     !(fsw->type () & (CompWindowTypeDockMask |
  58.                               CompWindowTypeFullscreenMask)) &&
  59.                     !fsw->overrideRedirect ())
  60.                     windowsLostFocus.push_back (fsw);
  61.  
  62.                     if (fsw->type () & CompWindowTypeFullscreenMask)
  63.                     {
  64.                     ServerLock lock (screen->serverGrabInterface ());
  65.  
  66.                     /* This will be the window that we must lower relative to */
  67.                     CompWindow *sibling =
  68.                         PrivateWindow::findValidStackSiblingBelow (active,
  69.                                                fsw,
  70.                                                lock);
  71.  
  72.                     if (sibling)
  73.                     {
  74.                         for (CompWindowList::reverse_iterator rit = windowsLostFocus.rbegin ();
  75.                          rit != windowsLostFocus.rend (); ++rit)
  76.                         {
  77.                         (*rit)->restackAbove (sibling);
  78.                         }
  79.                     }
  80.  
  81.                     break;
  82.                     }
  83.                 }
  84.                 }
  85.  
  86.                 active->changeState (active->focused () ?
  87.                          active->state () | CompWindowStateFocusedMask :
  88.                          active->state () & ~CompWindowStateFocusedMask);
  89.  
  90.                 active->priv->updatePassiveButtonGrabs ();
  91.             }
  92.  
  93.             if (w->focused ())
  94.                 state |= w->state () | CompWindowStateFocusedMask;
  95.             else
  96.                 state &= w->state () & ~CompWindowStateFocusedMask;
  97.  
  98.             w->priv->updatePassiveButtonGrabs ();
  99.  
  100.             addToCurrentActiveWindowHistory (w->id ());
  101.  
  102.             XChangeProperty (privateScreen.dpy , privateScreen.rootWindow(),
  103.                      Atoms::winActive,
  104.                      XA_WINDOW, 32, PropModeReplace,
  105.                      (unsigned char *) &privateScreen.orphanData.activeWindow, 1);
  106.  
  107.             w->windowNotify (CompWindowNotifyFocusChange);
  108.             }
  109.  
  110.             state &= ~CompWindowStateDemandsAttentionMask;
  111.             w->changeState (state);
  112.             }
  113.         else if (event->xfocus.window == privateScreen.rootWindow())
  114.         {
  115.             /* Don't ever let the focus go to the root
  116.              * window except in grab cases
  117.              *
  118.              * FIXME: There might be a case where we have to
  119.              * handle root windows of other screens here, but
  120.              * the other window managers should handle that
  121.              */
  122.  
  123.             if (event->xfocus.detail == NotifyDetailNone ||
  124.             (event->xfocus.mode == NotifyNormal &&
  125.              event->xfocus.detail == NotifyInferior))
  126.             {
  127.             privateScreen.orphanData.activeWindow = None;
  128.  
  129.             if (event->xfocus.detail == NotifyDetailNone ||
  130.                 (event->xfocus.mode == NotifyNormal &&
  131.                  event->xfocus.detail == NotifyInferior))
  132.             {
  133.                 screen->focusDefaultWindow ();
  134.             }
  135.             }
  136.         }
  137.  
  138.         /* Ensure that docks are stacked in the right place
  139.          *
  140.          * When a normal window gets the focus and is above a
  141.          * fullscreen window, restack the docks to be above
  142.          * the highest level mapped and visible normal window,
  143.          * otherwise put them above the highest fullscreen window
  144.          */
  145.         if (w)
  146.         {
  147.             ServerLock lock (screen->serverGrabInterface ());
  148.             if (PrivateWindow::stackDocks (w,
  149.                            dockWindows,
  150.                            &xwc,
  151.                            &mask,
  152.                            lock))
  153.             {
  154.             Window sibling = xwc.sibling;
  155.             xwc.stack_mode = Above;
  156.  
  157.             /* Then update the dock windows */
  158.             foreach (CompWindow *dw, dockWindows)
  159.             {
  160.                 xwc.sibling = sibling;
  161.                 dw->restackAndConfigureXWindow (mask, &xwc, lock);
  162.             }
  163.             }
  164.         }
  165.  
  166.         }
  167.     }
  168.     else
  169.     {
  170.         CompWindow *w;
  171.  
  172.         w = screen->findWindow (privateScreen.orphanData.activeWindow);
  173.  
  174.         setNextActiveWindow(None);
  175.         privateScreen.orphanData.activeWindow = None;
  176.  
  177.         if (w)
  178.         w->priv->updatePassiveButtonGrabs ();
  179.     }
  180.     }
  181.     break;
  182.     case FocusOut:
  183.     if (event->xfocus.mode == NotifyUngrab)
  184.         privateScreen.eventManager.ungrabNotified ();
  185.     else if (event->xfocus.mode == NotifyWhileGrabbed)
  186.         privateScreen.eventManager.grabNotified ();
  187.     break;
  188.     case EnterNotify:
  189.     if (event->xcrossing.root == privateScreen.rootWindow())
  190.         w = findTopLevelWindow (event->xcrossing.window);
  191.     else
  192.         w = NULL;
  193.  
  194.     if (w && w->id () != below)
  195.     {
  196.         below = w->id ();
  197.  
  198.         if (!privateScreen.optionGetClickToFocus () &&
  199.         privateScreen.eventManager.grabsEmpty () &&
  200.         event->xcrossing.mode   != NotifyGrab                &&
  201.         event->xcrossing.detail != NotifyInferior)
  202.         {
  203.         bool raise;
  204.         int  delay;
  205.         int  mask = CompWindowTypeDockMask;
  206.  
  207.         raise = privateScreen.optionGetAutoraise ();
  208.         delay = privateScreen.optionGetAutoraiseDelay ();
  209.  
  210.         if (!privateScreen.optionGetFocusDesktop ())
  211.             mask = mask | CompWindowTypeDesktopMask;
  212.  
  213.         if (autoRaiseTimer_.active () &&
  214.             autoRaiseWindow_ != w->id ())
  215.         {
  216.             autoRaiseTimer_.stop ();
  217.         }
  218.  
  219.         if (w->type () & ~mask)
  220.         {
  221.             w->moveInputFocusTo ();
  222.  
  223.             if (raise)
  224.             {
  225.             if (delay > 0)
  226.             {
  227.                 autoRaiseWindow_ = w->id ();
  228.                 autoRaiseTimer_.start (
  229.                 boost::bind (autoRaiseTimeout, this),
  230.                 delay, (unsigned int) ((float) delay * 1.2));
  231.             }
  232.             else
  233.             {
  234.                 CompStackingUpdateMode mode =
  235.                 CompStackingUpdateModeNormal;
  236.  
  237.                 w->updateAttributes (mode);
  238.             }
  239.             }
  240.         }
  241.         }
  242.     }
  243.     break;
  244.     case LeaveNotify:
  245.     if (event->xcrossing.detail != NotifyInferior)
  246.     {
  247.         if (event->xcrossing.window == below)
  248.         below = None;
  249.     }
  250.     break;
  251.     default:
  252.     if (privateScreen.xShape.isEnabled () &&
  253.          event->type == privateScreen.xShape.get () + ShapeNotify)
  254.     {
  255.         w = findWindow (((XShapeEvent *) event)->window);
  256.         if (w)
  257.         {
  258.         if (w->mapNum ())
  259.             w->priv->updateRegion ();
  260.         }
  261.     }
  262.     else if (event->type == privateScreen.xSync.get () + XSyncAlarmNotify)
  263.     {
  264.         XSyncAlarmNotifyEvent *sa;
  265.  
  266.         sa = (XSyncAlarmNotifyEvent *) event;
  267.  
  268.  
  269.         for (cps::WindowManager::iterator i = windowManager.begin(); i != windowManager.end(); ++i)
  270.         {
  271.         CompWindow* const w(*i);
  272.         if (w->priv->syncAlarm == sa->alarm)
  273.         {
  274.             w->priv->handleSyncAlarm ();
  275.             break;
  276.         }
  277.         }
  278.     }
  279.     break;
  280.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement