Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case FocusIn:
- {
- if (!XGetWindowAttributes (privateScreen.dpy, event->xfocus.window, &wa))
- privateScreen.setDefaultWindowAttributes (&wa);
- /* If the call to XGetWindowAttributes failed it means
- * the window was destroyed, so track the focus change
- * anyways since we need to increment activeNum
- * and the passive button grabs and then we will
- * get the DestroyNotify later and change the focus
- * there
- */
- if (wa.root == privateScreen.rootWindow())
- {
- if (event->xfocus.mode == NotifyGrab)
- privateScreen.eventManager.grabNotified ();
- else if (event->xfocus.mode == NotifyUngrab)
- privateScreen.eventManager.ungrabNotified ();
- else
- {
- CompWindowList dockWindows;
- XWindowChanges xwc;
- unsigned int mask;
- w = findTopLevelWindow (event->xfocus.window);
- if (w && w->managed ())
- {
- unsigned int state = w->state ();
- if (getNextActiveWindow() == event->xfocus.window)
- setNextActiveWindow(None);
- if (w->id () != privateScreen.orphanData.activeWindow)
- {
- CompWindow *active = screen->findWindow (privateScreen.orphanData.activeWindow);
- privateScreen.orphanData.activeWindow = w->id ();
- w->priv->activeNum = nextActiveNum();
- if (active)
- {
- CompWindowList windowsLostFocus;
- /* If this window lost focus and was above a fullscreen window
- * and is no longer capable of being focused (eg, it is
- * not visible on this viewport) then we need to check if
- * any other windows below it are also now no longer capable
- * of being focused and restack them in the highest position
- * below docks that they are allowed to take */
- if (!active->focus ())
- {
- windowsLostFocus.push_back (active);
- for (CompWindow *fsw = active->prev; fsw; fsw = fsw->prev)
- {
- if (!fsw->focus () &&
- fsw->managed () &&
- !(fsw->type () & (CompWindowTypeDockMask |
- CompWindowTypeFullscreenMask)) &&
- !fsw->overrideRedirect ())
- windowsLostFocus.push_back (fsw);
- if (fsw->type () & CompWindowTypeFullscreenMask)
- {
- ServerLock lock (screen->serverGrabInterface ());
- /* This will be the window that we must lower relative to */
- CompWindow *sibling =
- PrivateWindow::findValidStackSiblingBelow (active,
- fsw,
- lock);
- if (sibling)
- {
- for (CompWindowList::reverse_iterator rit = windowsLostFocus.rbegin ();
- rit != windowsLostFocus.rend (); ++rit)
- {
- (*rit)->restackAbove (sibling);
- }
- }
- break;
- }
- }
- }
- active->changeState (active->focused () ?
- active->state () | CompWindowStateFocusedMask :
- active->state () & ~CompWindowStateFocusedMask);
- active->priv->updatePassiveButtonGrabs ();
- }
- if (w->focused ())
- state |= w->state () | CompWindowStateFocusedMask;
- else
- state &= w->state () & ~CompWindowStateFocusedMask;
- w->priv->updatePassiveButtonGrabs ();
- addToCurrentActiveWindowHistory (w->id ());
- XChangeProperty (privateScreen.dpy , privateScreen.rootWindow(),
- Atoms::winActive,
- XA_WINDOW, 32, PropModeReplace,
- (unsigned char *) &privateScreen.orphanData.activeWindow, 1);
- w->windowNotify (CompWindowNotifyFocusChange);
- }
- state &= ~CompWindowStateDemandsAttentionMask;
- w->changeState (state);
- }
- else if (event->xfocus.window == privateScreen.rootWindow())
- {
- /* Don't ever let the focus go to the root
- * window except in grab cases
- *
- * FIXME: There might be a case where we have to
- * handle root windows of other screens here, but
- * the other window managers should handle that
- */
- if (event->xfocus.detail == NotifyDetailNone ||
- (event->xfocus.mode == NotifyNormal &&
- event->xfocus.detail == NotifyInferior))
- {
- privateScreen.orphanData.activeWindow = None;
- if (event->xfocus.detail == NotifyDetailNone ||
- (event->xfocus.mode == NotifyNormal &&
- event->xfocus.detail == NotifyInferior))
- {
- screen->focusDefaultWindow ();
- }
- }
- }
- /* Ensure that docks are stacked in the right place
- *
- * When a normal window gets the focus and is above a
- * fullscreen window, restack the docks to be above
- * the highest level mapped and visible normal window,
- * otherwise put them above the highest fullscreen window
- */
- if (w)
- {
- ServerLock lock (screen->serverGrabInterface ());
- if (PrivateWindow::stackDocks (w,
- dockWindows,
- &xwc,
- &mask,
- lock))
- {
- Window sibling = xwc.sibling;
- xwc.stack_mode = Above;
- /* Then update the dock windows */
- foreach (CompWindow *dw, dockWindows)
- {
- xwc.sibling = sibling;
- dw->restackAndConfigureXWindow (mask, &xwc, lock);
- }
- }
- }
- }
- }
- else
- {
- CompWindow *w;
- w = screen->findWindow (privateScreen.orphanData.activeWindow);
- setNextActiveWindow(None);
- privateScreen.orphanData.activeWindow = None;
- if (w)
- w->priv->updatePassiveButtonGrabs ();
- }
- }
- break;
- case FocusOut:
- if (event->xfocus.mode == NotifyUngrab)
- privateScreen.eventManager.ungrabNotified ();
- else if (event->xfocus.mode == NotifyWhileGrabbed)
- privateScreen.eventManager.grabNotified ();
- break;
- case EnterNotify:
- if (event->xcrossing.root == privateScreen.rootWindow())
- w = findTopLevelWindow (event->xcrossing.window);
- else
- w = NULL;
- if (w && w->id () != below)
- {
- below = w->id ();
- if (!privateScreen.optionGetClickToFocus () &&
- privateScreen.eventManager.grabsEmpty () &&
- event->xcrossing.mode != NotifyGrab &&
- event->xcrossing.detail != NotifyInferior)
- {
- bool raise;
- int delay;
- int mask = CompWindowTypeDockMask;
- raise = privateScreen.optionGetAutoraise ();
- delay = privateScreen.optionGetAutoraiseDelay ();
- if (!privateScreen.optionGetFocusDesktop ())
- mask = mask | CompWindowTypeDesktopMask;
- if (autoRaiseTimer_.active () &&
- autoRaiseWindow_ != w->id ())
- {
- autoRaiseTimer_.stop ();
- }
- if (w->type () & ~mask)
- {
- w->moveInputFocusTo ();
- if (raise)
- {
- if (delay > 0)
- {
- autoRaiseWindow_ = w->id ();
- autoRaiseTimer_.start (
- boost::bind (autoRaiseTimeout, this),
- delay, (unsigned int) ((float) delay * 1.2));
- }
- else
- {
- CompStackingUpdateMode mode =
- CompStackingUpdateModeNormal;
- w->updateAttributes (mode);
- }
- }
- }
- }
- }
- break;
- case LeaveNotify:
- if (event->xcrossing.detail != NotifyInferior)
- {
- if (event->xcrossing.window == below)
- below = None;
- }
- break;
- default:
- if (privateScreen.xShape.isEnabled () &&
- event->type == privateScreen.xShape.get () + ShapeNotify)
- {
- w = findWindow (((XShapeEvent *) event)->window);
- if (w)
- {
- if (w->mapNum ())
- w->priv->updateRegion ();
- }
- }
- else if (event->type == privateScreen.xSync.get () + XSyncAlarmNotify)
- {
- XSyncAlarmNotifyEvent *sa;
- sa = (XSyncAlarmNotifyEvent *) event;
- for (cps::WindowManager::iterator i = windowManager.begin(); i != windowManager.end(); ++i)
- {
- CompWindow* const w(*i);
- if (w->priv->syncAlarm == sa->alarm)
- {
- w->priv->handleSyncAlarm ();
- break;
- }
- }
- }
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement