bool RotateScreen::rotateWithWindow (CompAction *action, CompAction::State state, CompOption::Vector &options, int direction) { if (screen->vpSize ().width () < 2 || !direction) return false; Window xid = CompOption::getIntOptionNamed (options, "window"); if (mMoveWindow != xid) { releaseMoveWindow (); if (!mGrabIndex && !mMoving) { CompWindow *w = screen->findWindow (xid); if (w && !(w->type () & (CompWindowTypeDesktopMask | CompWindowTypeDockMask)) && !(w->state () & CompWindowStateStickyMask)) { mMoveWindow = w->id (); mMoveWindowX = w->x (); if (optionGetRaiseOnRotate ()) w->raise (); } } } if (!mGrabIndex) { CompOption::Vector o (0); o.push_back (CompOption ("root", CompOption::TypeInt)); o.push_back (CompOption ("x", CompOption::TypeInt)); o.push_back (CompOption ("y", CompOption::TypeInt)); o[0].value ().set ((int) screen->root ()); o[1].value ().set (CompOption::getIntOptionNamed (options, "x", 0)); o[2].value ().set (CompOption::getIntOptionNamed (options, "y", 0)); initiate (NULL, 0, o); } if (mGrabIndex) { mMoving = true; mMoveTo += 360.0f / screen->vpSize ().width () * direction; mGrabbed = false; cScreen->damageScreen (); } return false; }
bool KeyboardNavigation::initiate (CompAction *action, CompAction::State state, CompOption::Vector &option, FocusDirection direction) { CompWindow *window = screen->findWindow( screen->activeWindow() ); if (window) { /* Don't allow focus change for certain special windows */ if (window->overrideRedirect() || (window->type() & (CompWindowTypeDesktopMask | CompWindowTypeDockMask))) { return false; } DEBUG_LOG("Initiating search for nearest window: " << direction); NearestWindow nearestWindow (window, direction); screen->forEachWindow( boost::bind( &KeyboardNavigation::NearestWindow::inspectWindow, &nearestWindow, _1 ) ); CompWindow *focusWindow = nearestWindow.result(); if (focusWindow != NULL) { DEBUG_LOG("Found focusWindow: " << focusWindow->id() << " " << focusWindow->x() << "x" << focusWindow->y()); focusWindow->moveInputFocusTo(); focusWindow->activate(); return true; } else { DEBUG_LOG("Unable to find focus window!"); } } return false; }
bool WallScreen::moveViewport (int x, int y, Window moveWin) { CompOption::Vector o(0); if (!x && !y) return false; if (screen->otherGrabExist ("move", "switcher", "group-drag", "wall", 0)) return false; if (!checkDestination (x, y)) return false; if (moveWindow != moveWin) { CompWindow *w; releaseMoveWindow (); w = screen->findWindow (moveWin); if (w) { if (!(w->type () & (CompWindowTypeDesktopMask | CompWindowTypeDockMask))) { if (!(w->state () & CompWindowStateStickyMask)) { moveWindow = w->id (); moveWindowX = w->x (); moveWindowY = w->y (); w->raise (); } } } } if (!moving) { curPosX = screen->vp ().x (); curPosY = screen->vp ().y (); } gotoX = screen->vp ().x () - x; gotoY = screen->vp ().y () - y; determineMovementAngle (); screen->handleCompizEvent ("wall", "start_viewport_switch", o); if (!grabIndex) grabIndex = screen->pushGrab (screen->invisibleCursor (), "wall"); screen->moveViewport (x, y, true); moving = true; focusDefault = true; boxOutputDevice = screen->outputDeviceForPoint (pointerX, pointerY); if (optionGetShowSwitcher ()) boxTimeout = optionGetPreviewTimeout () * 1000; else boxTimeout = 0; timer = optionGetSlideDuration () * 1000; cScreen->damageScreen (); return true; }
void RotateScreen::preparePaint (int msSinceLastPaint) { float oldXrot = mXrot + mBaseXrot; if (mGrabIndex || mMoving) { float amount = msSinceLastPaint * 0.05f * optionGetSpeed (); int steps = amount / (0.5f * optionGetTimestep ()); if (!steps) steps = 1; float chunk = amount / (float) steps; while (steps--) { mXrot += mXVelocity * chunk; mYrot += mYVelocity * chunk; if (mXrot > 360.0f / screen->vpSize ().width ()) { mBaseXrot += 360.0f / screen->vpSize ().width (); mXrot -= 360.0f / screen->vpSize ().width (); } else if (mXrot < 0.0f) { mBaseXrot -= 360.0f / screen->vpSize ().width (); mXrot += 360.0f / screen->vpSize ().width (); } if (cubeScreen->invert () == -1) { if (mYrot > 45.0f) { mYVelocity = 0.0f; mYrot = 45.0f; } else if (mYrot < -45.0f) { mYVelocity = 0.0f; mYrot = -45.0f; } } else { if (mYrot > 100.0f) { mYVelocity = 0.0f; mYrot = 100.0f; } else if (mYrot < -100.0f) { mYVelocity = 0.0f; mYrot = -100.0f; } } if (mGrabbed) { mXVelocity /= 1.25f; mYVelocity /= 1.25f; if (fabs (mXVelocity) < 0.01f) mXVelocity = 0.0f; if (fabs (mYVelocity) < 0.01f) mYVelocity = 0.0f; } else if (adjustVelocity (screen->vpSize ().width (), cubeScreen->invert ())) { mXVelocity = 0.0f; mYVelocity = 0.0f; if (fabs (mYrot) < 0.1f) { CompOption::Vector o (0); int tx; float xrot = mBaseXrot + mXrot; if (xrot < 0.0f) tx = (screen->vpSize ().width () * xrot / 360.0f) - 0.5f; else tx = (screen->vpSize ().width () * xrot / 360.0f) + 0.5f; /* flag end of rotation */ cubeScreen->rotationState (CubeScreen::RotationNone); screen->moveViewport (tx, 0, true); mBaseXrot = mMoveTo = mXrot = mYrot = 0.0f; mMoving = false; if (mGrabIndex) { screen->removeGrab (mGrabIndex, &mSavedPointer); mGrabIndex = 0; } if (mMoveWindow) { CompWindow *w = screen->findWindow (mMoveWindow); if (w) w->move (mMoveWindowX - w->x (), 0); } /* only focus default window if switcher isn't active */ else if (!screen->grabExist ("switcher")) screen->focusDefaultWindow (); mMoveWindow = 0; screen->handleCompizEvent ("rotate", "end_viewport_switch", o); } break; } } if (mMoveWindow) { CompWindow *w = screen->findWindow (mMoveWindow); if (w) { float xrot = (screen->vpSize ().width () * (mBaseXrot + mXrot)) / 360.0f; w->moveToViewportPosition (mMoveWindowX - xrot * screen->width (), w->y (), false); } } } if (mMoving) { if (fabs (mXrot + mBaseXrot + mMoveTo) <= 180 / screen->vpSize ().width ()) mProgress = fabs (mXrot + mBaseXrot + mMoveTo) / 180 / screen->vpSize ().width (); else if (fabs (mXrot + mBaseXrot) <= 180 / screen->vpSize ().width ()) mProgress = fabs (mXrot + mBaseXrot) / 180 / screen->vpSize ().width (); else { mProgress += fabs (mXrot + mBaseXrot - oldXrot) / 180 / (screen->vpSize ().width ()); mProgress = MIN (mProgress, 1.0); } } else if (mProgress != 0.0f || mGrabbed) { float amount = msSinceLastPaint * 0.05f * optionGetSpeed (); int steps = amount / (0.5f * optionGetTimestep ()); if (!steps) steps = 1; float chunk = amount / (float) steps; while (steps--) { float dt; if (mGrabbed) dt = 1.0 - mProgress; else dt = 0.0f - mProgress; float adjust = dt * 0.15f; float tamount = fabs (dt) * 1.5f; if (tamount < 0.2f) tamount = 0.2f; else if (tamount > 2.0f) tamount = 2.0f; mProgressVelocity = (tamount * mProgressVelocity + adjust) / (tamount + 1.0f); mProgress += mProgressVelocity * chunk; if (fabs (dt) < 0.01f && fabs (mProgressVelocity) < 0.0001f) { if (mGrabbed) mProgress = 1.0f; else mProgress = 0.0f; break; } } } if (cubeScreen->invert () == 1 && !cubeScreen->unfolded ()) mZoomTranslate = optionGetZoom () * mProgress; else mZoomTranslate = 0.0; cScreen->preparePaint (msSinceLastPaint); }