Changeset View
Changeset View
Standalone View
Standalone View
effects/desktopgrid/desktopgrid.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | |||||
52 | DesktopGridEffect::DesktopGridEffect() | 52 | DesktopGridEffect::DesktopGridEffect() | ||
53 | : activated(false) | 53 | : activated(false) | ||
54 | , timeline() | 54 | , timeline() | ||
55 | , keyboardGrab(false) | 55 | , keyboardGrab(false) | ||
56 | , wasWindowMove(false) | 56 | , wasWindowMove(false) | ||
57 | , wasWindowCopy(false) | 57 | , wasWindowCopy(false) | ||
58 | , wasDesktopMove(false) | 58 | , wasDesktopMove(false) | ||
59 | , isValidMove(false) | 59 | , isValidMove(false) | ||
60 | , windowMove(NULL) | 60 | , windowMove(nullptr) | ||
61 | , windowMoveDiff() | 61 | , windowMoveDiff() | ||
62 | , gridSize() | 62 | , gridSize() | ||
63 | , orientation(Qt::Horizontal) | 63 | , orientation(Qt::Horizontal) | ||
64 | , activeCell(1, 1) | 64 | , activeCell(1, 1) | ||
65 | , scale() | 65 | , scale() | ||
66 | , unscaledBorder() | 66 | , unscaledBorder() | ||
67 | , scaledSize() | 67 | , scaledSize() | ||
68 | , scaledOffset() | 68 | , scaledOffset() | ||
69 | , m_proxy(0) | 69 | , m_proxy(nullptr) | ||
70 | , m_activateAction(new QAction(this)) | 70 | , m_activateAction(new QAction(this)) | ||
71 | { | 71 | { | ||
72 | initConfig<DesktopGridConfig>(); | 72 | initConfig<DesktopGridConfig>(); | ||
73 | // Load shortcuts | 73 | // Load shortcuts | ||
74 | QAction* a = m_activateAction; | 74 | QAction* a = m_activateAction; | ||
75 | a->setObjectName(QStringLiteral("ShowDesktopGrid")); | 75 | a->setObjectName(QStringLiteral("ShowDesktopGrid")); | ||
76 | a->setText(i18n("Show Desktop Grid")); | 76 | a->setText(i18n("Show Desktop Grid")); | ||
77 | KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F8); | 77 | KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F8); | ||
▲ Show 20 Lines • Show All 345 Lines • ▼ Show 20 Line(s) | |||||
423 | } | 423 | } | ||
424 | 424 | | |||
425 | void DesktopGridEffect::slotWindowClosed(EffectWindow* w) | 425 | void DesktopGridEffect::slotWindowClosed(EffectWindow* w) | ||
426 | { | 426 | { | ||
427 | if (!activated && timeline.currentValue() == 0) | 427 | if (!activated && timeline.currentValue() == 0) | ||
428 | return; | 428 | return; | ||
429 | if (w == windowMove) { | 429 | if (w == windowMove) { | ||
430 | effects->setElevatedWindow(windowMove, false); | 430 | effects->setElevatedWindow(windowMove, false); | ||
431 | windowMove = NULL; | 431 | windowMove = nullptr; | ||
432 | } | 432 | } | ||
433 | if (isUsingPresentWindows()) { | 433 | if (isUsingPresentWindows()) { | ||
434 | foreach (const int i, desktopList(w)) { | 434 | foreach (const int i, desktopList(w)) { | ||
435 | WindowMotionManager& manager = m_managers[i*effects->numScreens()+w->screen()]; | 435 | WindowMotionManager& manager = m_managers[i*effects->numScreens()+w->screen()]; | ||
436 | manager.unmanage(w); | 436 | manager.unmanage(w); | ||
437 | m_proxy->calculateWindowTransformations(manager.managedWindows(), w->screen(), manager); | 437 | m_proxy->calculateWindowTransformations(manager.managedWindows(), w->screen(), manager); | ||
438 | } | 438 | } | ||
439 | } | 439 | } | ||
440 | effects->addRepaintFull(); | 440 | effects->addRepaintFull(); | ||
441 | } | 441 | } | ||
442 | 442 | | |||
443 | void DesktopGridEffect::slotWindowDeleted(EffectWindow* w) | 443 | void DesktopGridEffect::slotWindowDeleted(EffectWindow* w) | ||
444 | { | 444 | { | ||
445 | if (w == windowMove) | 445 | if (w == windowMove) | ||
446 | windowMove = 0; | 446 | windowMove = nullptr; | ||
447 | foreach (DesktopButtonsView *view, m_desktopButtonsViews) { | 447 | foreach (DesktopButtonsView *view, m_desktopButtonsViews) { | ||
448 | if (view->effectWindow && view->effectWindow == w) { | 448 | if (view->effectWindow && view->effectWindow == w) { | ||
449 | view->effectWindow = nullptr; | 449 | view->effectWindow = nullptr; | ||
450 | break; | 450 | break; | ||
451 | } | 451 | } | ||
452 | } | 452 | } | ||
453 | if (isUsingPresentWindows()) { | 453 | if (isUsingPresentWindows()) { | ||
454 | for (QList<WindowMotionManager>::iterator it = m_managers.begin(), | 454 | for (QList<WindowMotionManager>::iterator it = m_managers.begin(), | ||
Show All 34 Lines | 486 | if (view->geometry().contains(me->pos())) { | |||
489 | view->windowInputMouseEvent(&event); | 489 | view->windowInputMouseEvent(&event); | ||
490 | return; | 490 | return; | ||
491 | } | 491 | } | ||
492 | } | 492 | } | ||
493 | } | 493 | } | ||
494 | 494 | | |||
495 | if (e->type() == QEvent::MouseMove) { | 495 | if (e->type() == QEvent::MouseMove) { | ||
496 | int d = posToDesktop(me->pos()); | 496 | int d = posToDesktop(me->pos()); | ||
497 | if (windowMove != NULL && | 497 | if (windowMove != nullptr && | ||
498 | (me->pos() - dragStartPos).manhattanLength() > QApplication::startDragDistance()) { | 498 | (me->pos() - dragStartPos).manhattanLength() > QApplication::startDragDistance()) { | ||
499 | // Handle window moving | 499 | // Handle window moving | ||
500 | if (!wasWindowMove) { // Activate on move | 500 | if (!wasWindowMove) { // Activate on move | ||
501 | if (isUsingPresentWindows()) { | 501 | if (isUsingPresentWindows()) { | ||
502 | foreach (const int i, desktopList(windowMove)) { | 502 | foreach (const int i, desktopList(windowMove)) { | ||
503 | WindowMotionManager& manager = m_managers[(i)*(effects->numScreens()) + windowMove->screen()]; | 503 | WindowMotionManager& manager = m_managers[(i)*(effects->numScreens()) + windowMove->screen()]; | ||
504 | if ((i + 1) == sourceDesktop) { | 504 | if ((i + 1) == sourceDesktop) { | ||
505 | const QRectF transformedGeo = manager.transformedGeometry(windowMove); | 505 | const QRectF transformedGeo = manager.transformedGeometry(windowMove); | ||
Show All 11 Lines | |||||
517 | m_proxy->calculateWindowTransformations(manager.managedWindows(), windowMove->screen(), manager); | 517 | m_proxy->calculateWindowTransformations(manager.managedWindows(), windowMove->screen(), manager); | ||
518 | } | 518 | } | ||
519 | wasWindowMove = true; | 519 | wasWindowMove = true; | ||
520 | } | 520 | } | ||
521 | } | 521 | } | ||
522 | if (windowMove->isMovable() && !isUsingPresentWindows()) { | 522 | if (windowMove->isMovable() && !isUsingPresentWindows()) { | ||
523 | wasWindowMove = true; | 523 | wasWindowMove = true; | ||
524 | int screen = effects->screenNumber(me->pos()); | 524 | int screen = effects->screenNumber(me->pos()); | ||
525 | effects->moveWindow(windowMove, unscalePos(me->pos(), NULL) + windowMoveDiff, true, 1.0 / scale[screen]); | 525 | effects->moveWindow(windowMove, unscalePos(me->pos(), nullptr) + windowMoveDiff, true, 1.0 / scale[screen]); | ||
526 | } | 526 | } | ||
527 | if (wasWindowMove) { | 527 | if (wasWindowMove) { | ||
528 | if (effects->waylandDisplay() && (me->modifiers() & Qt::ControlModifier)) { | 528 | if (effects->waylandDisplay() && (me->modifiers() & Qt::ControlModifier)) { | ||
529 | wasWindowCopy = true; | 529 | wasWindowCopy = true; | ||
530 | effects->defineCursor(Qt::DragCopyCursor); | 530 | effects->defineCursor(Qt::DragCopyCursor); | ||
531 | } else { | 531 | } else { | ||
532 | wasWindowCopy = false; | 532 | wasWindowCopy = false; | ||
533 | effects->defineCursor(Qt::ClosedHandCursor); | 533 | effects->defineCursor(Qt::ClosedHandCursor); | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
598 | } | 598 | } | ||
599 | } | 599 | } | ||
600 | if (e->type() == QEvent::MouseButtonPress) { | 600 | if (e->type() == QEvent::MouseButtonPress) { | ||
601 | if (me->buttons() == Qt::LeftButton) { | 601 | if (me->buttons() == Qt::LeftButton) { | ||
602 | isValidMove = true; | 602 | isValidMove = true; | ||
603 | dragStartPos = me->pos(); | 603 | dragStartPos = me->pos(); | ||
604 | sourceDesktop = posToDesktop(me->pos()); | 604 | sourceDesktop = posToDesktop(me->pos()); | ||
605 | bool isDesktop = (me->modifiers() & Qt::ShiftModifier); | 605 | bool isDesktop = (me->modifiers() & Qt::ShiftModifier); | ||
606 | EffectWindow* w = isDesktop ? NULL : windowAt(me->pos()); | 606 | EffectWindow* w = isDesktop ? nullptr : windowAt(me->pos()); | ||
607 | if (w != NULL) | 607 | if (w != nullptr) | ||
608 | isDesktop = w->isDesktop(); | 608 | isDesktop = w->isDesktop(); | ||
609 | if (isDesktop) | 609 | if (isDesktop) | ||
610 | m_originalMovingDesktop = posToDesktop(me->pos()); | 610 | m_originalMovingDesktop = posToDesktop(me->pos()); | ||
611 | else | 611 | else | ||
612 | m_originalMovingDesktop = 0; | 612 | m_originalMovingDesktop = 0; | ||
613 | if (w != NULL && !w->isDesktop() && (w->isMovable() || w->isMovableAcrossScreens() || isUsingPresentWindows())) { | 613 | if (w != nullptr && !w->isDesktop() && (w->isMovable() || w->isMovableAcrossScreens() || isUsingPresentWindows())) { | ||
614 | // Prepare it for moving | 614 | // Prepare it for moving | ||
615 | windowMoveDiff = w->pos() - unscalePos(me->pos(), NULL); | 615 | windowMoveDiff = w->pos() - unscalePos(me->pos(), nullptr); | ||
616 | windowMove = w; | 616 | windowMove = w; | ||
617 | effects->setElevatedWindow(windowMove, true); | 617 | effects->setElevatedWindow(windowMove, true); | ||
618 | } | 618 | } | ||
619 | } else if ((me->buttons() == Qt::MidButton || me->buttons() == Qt::RightButton) && windowMove == NULL) { | 619 | } else if ((me->buttons() == Qt::MidButton || me->buttons() == Qt::RightButton) && windowMove == nullptr) { | ||
620 | EffectWindow* w = windowAt(me->pos()); | 620 | EffectWindow* w = windowAt(me->pos()); | ||
621 | if (w && w->isDesktop()) { | 621 | if (w && w->isDesktop()) { | ||
622 | w = nullptr; | 622 | w = nullptr; | ||
623 | } | 623 | } | ||
624 | if (w != NULL) { | 624 | if (w != nullptr) { | ||
625 | const int desktop = posToDesktop(me->pos()); | 625 | const int desktop = posToDesktop(me->pos()); | ||
626 | if (w->isOnAllDesktops()) { | 626 | if (w->isOnAllDesktops()) { | ||
627 | effects->windowToDesktop(w, desktop); | 627 | effects->windowToDesktop(w, desktop); | ||
628 | } else { | 628 | } else { | ||
629 | effects->windowToDesktop(w, NET::OnAllDesktops); | 629 | effects->windowToDesktop(w, NET::OnAllDesktops); | ||
630 | } | 630 | } | ||
631 | const bool isOnAllDesktops = w->isOnAllDesktops(); | 631 | const bool isOnAllDesktops = w->isOnAllDesktops(); | ||
632 | if (isUsingPresentWindows()) { | 632 | if (isUsingPresentWindows()) { | ||
Show All 37 Lines | 669 | if (i + 1 == targetDesktop) { | |||
670 | // for the desktop the window is dropped on, we use the current geometry | 670 | // for the desktop the window is dropped on, we use the current geometry | ||
671 | manager.setTransformedGeometry(windowMove, moveGeometryToDesktop(targetDesktop)); | 671 | manager.setTransformedGeometry(windowMove, moveGeometryToDesktop(targetDesktop)); | ||
672 | } | 672 | } | ||
673 | m_proxy->calculateWindowTransformations(manager.managedWindows(), windowMove->screen(), manager); | 673 | m_proxy->calculateWindowTransformations(manager.managedWindows(), windowMove->screen(), manager); | ||
674 | } | 674 | } | ||
675 | effects->addRepaintFull(); | 675 | effects->addRepaintFull(); | ||
676 | } | 676 | } | ||
677 | effects->setElevatedWindow(windowMove, false); | 677 | effects->setElevatedWindow(windowMove, false); | ||
678 | windowMove = NULL; | 678 | windowMove = nullptr; | ||
679 | } | 679 | } | ||
680 | wasWindowMove = false; | 680 | wasWindowMove = false; | ||
681 | wasWindowCopy = false; | 681 | wasWindowCopy = false; | ||
682 | wasDesktopMove = false; | 682 | wasDesktopMove = false; | ||
683 | } | 683 | } | ||
684 | } | 684 | } | ||
685 | 685 | | |||
686 | void DesktopGridEffect::grabbedKeyboardEvent(QKeyEvent* e) | 686 | void DesktopGridEffect::grabbedKeyboardEvent(QKeyEvent* e) | ||
687 | { | 687 | { | ||
688 | if (timeline.currentValue() != 1) // Block user input during animations | 688 | if (timeline.currentValue() != 1) // Block user input during animations | ||
689 | return; | 689 | return; | ||
690 | if (windowMove != NULL) | 690 | if (windowMove != nullptr) | ||
691 | return; | 691 | return; | ||
692 | if (e->type() == QEvent::KeyPress) { | 692 | if (e->type() == QEvent::KeyPress) { | ||
693 | // check for global shortcuts | 693 | // check for global shortcuts | ||
694 | // HACK: keyboard grab disables the global shortcuts so we have to check for global shortcut (bug 156155) | 694 | // HACK: keyboard grab disables the global shortcuts so we have to check for global shortcut (bug 156155) | ||
695 | if (shortcut.contains(e->key() + e->modifiers())) { | 695 | if (shortcut.contains(e->key() + e->modifiers())) { | ||
696 | toggle(); | 696 | toggle(); | ||
697 | return; | 697 | return; | ||
698 | } | 698 | } | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 809 | { | |||
818 | double scaledY = /*interpolate( | 818 | double scaledY = /*interpolate( | ||
819 | ( pos.y() - screenGeom.y() + unscaledBorder[screen] / 2.0 ) / ( screenGeom.height() + unscaledBorder[screen] ) + activeCell.y() - 1,*/ | 819 | ( pos.y() - screenGeom.y() + unscaledBorder[screen] / 2.0 ) / ( screenGeom.height() + unscaledBorder[screen] ) + activeCell.y() - 1,*/ | ||
820 | (pos.y() - scaledOffset[screen].y() + double(border) / 2.0) / (scaledSize[screen].height() + border)/*, | 820 | (pos.y() - scaledOffset[screen].y() + double(border) / 2.0) / (scaledSize[screen].height() + border)/*, | ||
821 | progress )*/; | 821 | progress )*/; | ||
822 | int gx = qBound(0, int(scaledX), gridSize.width() - 1); // Zero-based | 822 | int gx = qBound(0, int(scaledX), gridSize.width() - 1); // Zero-based | ||
823 | int gy = qBound(0, int(scaledY), gridSize.height() - 1); | 823 | int gy = qBound(0, int(scaledY), gridSize.height() - 1); | ||
824 | scaledX -= gx; | 824 | scaledX -= gx; | ||
825 | scaledY -= gy; | 825 | scaledY -= gy; | ||
826 | if (desktop != NULL) { | 826 | if (desktop != nullptr) { | ||
827 | if (orientation == Qt::Horizontal) | 827 | if (orientation == Qt::Horizontal) | ||
828 | *desktop = gy * gridSize.width() + gx + 1; | 828 | *desktop = gy * gridSize.width() + gx + 1; | ||
829 | else | 829 | else | ||
830 | *desktop = gx * gridSize.height() + gy + 1; | 830 | *desktop = gx * gridSize.height() + gy + 1; | ||
831 | } | 831 | } | ||
832 | 832 | | |||
833 | return QPoint( | 833 | return QPoint( | ||
834 | qBound( | 834 | qBound( | ||
Show All 39 Lines | 870 | { | |||
874 | EffectWindowList::Iterator end = windows.end(); | 874 | EffectWindowList::Iterator end = windows.end(); | ||
875 | --end; | 875 | --end; | ||
876 | while (begin < end) | 876 | while (begin < end) | ||
877 | qSwap(*begin++, *end--); | 877 | qSwap(*begin++, *end--); | ||
878 | 878 | | |||
879 | int desktop; | 879 | int desktop; | ||
880 | pos = unscalePos(pos, &desktop); | 880 | pos = unscalePos(pos, &desktop); | ||
881 | if (desktop > effects->numberOfDesktops()) | 881 | if (desktop > effects->numberOfDesktops()) | ||
882 | return NULL; | 882 | return nullptr; | ||
883 | if (isUsingPresentWindows()) { | 883 | if (isUsingPresentWindows()) { | ||
884 | const int screen = effects->screenNumber(pos); | 884 | const int screen = effects->screenNumber(pos); | ||
885 | EffectWindow *w = | 885 | EffectWindow *w = | ||
886 | m_managers.at((desktop - 1) * (effects->numScreens()) + screen).windowAtPoint(pos, false); | 886 | m_managers.at((desktop - 1) * (effects->numScreens()) + screen).windowAtPoint(pos, false); | ||
887 | if (w) | 887 | if (w) | ||
888 | return w; | 888 | return w; | ||
889 | foreach (EffectWindow * w, windows) { | 889 | foreach (EffectWindow * w, windows) { | ||
890 | if (w->isOnDesktop(desktop) && w->isDesktop() && w->geometry().contains(pos)) | 890 | if (w->isOnDesktop(desktop) && w->isDesktop() && w->geometry().contains(pos)) | ||
891 | return w; | 891 | return w; | ||
892 | } | 892 | } | ||
893 | } else { | 893 | } else { | ||
894 | foreach (EffectWindow * w, windows) { | 894 | foreach (EffectWindow * w, windows) { | ||
895 | if (w->isOnDesktop(desktop) && w->isOnCurrentActivity() && !w->isMinimized() && w->geometry().contains(pos)) | 895 | if (w->isOnDesktop(desktop) && w->isOnCurrentActivity() && !w->isMinimized() && w->geometry().contains(pos)) | ||
896 | return w; | 896 | return w; | ||
897 | } | 897 | } | ||
898 | } | 898 | } | ||
899 | return NULL; | 899 | return nullptr; | ||
900 | } | 900 | } | ||
901 | 901 | | |||
902 | void DesktopGridEffect::setCurrentDesktop(int desktop) | 902 | void DesktopGridEffect::setCurrentDesktop(int desktop) | ||
903 | { | 903 | { | ||
904 | if (orientation == Qt::Horizontal) { | 904 | if (orientation == Qt::Horizontal) { | ||
905 | activeCell.setX((desktop - 1) % gridSize.width() + 1); | 905 | activeCell.setX((desktop - 1) % gridSize.width() + 1); | ||
906 | activeCell.setY((desktop - 1) / gridSize.width() + 1); | 906 | activeCell.setY((desktop - 1) / gridSize.width() + 1); | ||
907 | } else { | 907 | } else { | ||
▲ Show 20 Lines • Show All 310 Lines • ▼ Show 20 Line(s) | 1217 | if (desktopNameAlignment) { | |||
1218 | qDeleteAll(desktopNames); | 1218 | qDeleteAll(desktopNames); | ||
1219 | desktopNames.clear(); | 1219 | desktopNames.clear(); | ||
1220 | } | 1220 | } | ||
1221 | 1221 | | |||
1222 | if (keyboardGrab) | 1222 | if (keyboardGrab) | ||
1223 | effects->ungrabKeyboard(); | 1223 | effects->ungrabKeyboard(); | ||
1224 | keyboardGrab = false; | 1224 | keyboardGrab = false; | ||
1225 | effects->stopMouseInterception(this); | 1225 | effects->stopMouseInterception(this); | ||
1226 | effects->setActiveFullScreenEffect(0); | 1226 | effects->setActiveFullScreenEffect(nullptr); | ||
1227 | if (isUsingPresentWindows()) { | 1227 | if (isUsingPresentWindows()) { | ||
1228 | while (!m_managers.isEmpty()) { | 1228 | while (!m_managers.isEmpty()) { | ||
1229 | m_managers.first().unmanageAll(); | 1229 | m_managers.first().unmanageAll(); | ||
1230 | m_managers.removeFirst(); | 1230 | m_managers.removeFirst(); | ||
1231 | } | 1231 | } | ||
1232 | m_proxy = 0; | 1232 | m_proxy = nullptr; | ||
1233 | } | 1233 | } | ||
1234 | } | 1234 | } | ||
1235 | 1235 | | |||
1236 | void DesktopGridEffect::globalShortcutChanged(QAction *action, const QKeySequence& seq) | 1236 | void DesktopGridEffect::globalShortcutChanged(QAction *action, const QKeySequence& seq) | ||
1237 | { | 1237 | { | ||
1238 | if (action->objectName() != QStringLiteral("ShowDesktopGrid")) { | 1238 | if (action->objectName() != QStringLiteral("ShowDesktopGrid")) { | ||
1239 | return; | 1239 | return; | ||
1240 | } | 1240 | } | ||
Show All 10 Lines | 1250 | if ((*it).areWindowsMoving()) | |||
1251 | return true; | 1251 | return true; | ||
1252 | } | 1252 | } | ||
1253 | } | 1253 | } | ||
1254 | return false; | 1254 | return false; | ||
1255 | } | 1255 | } | ||
1256 | 1256 | | |||
1257 | bool DesktopGridEffect::isUsingPresentWindows() const | 1257 | bool DesktopGridEffect::isUsingPresentWindows() const | ||
1258 | { | 1258 | { | ||
1259 | return (m_proxy != NULL); | 1259 | return (m_proxy != nullptr); | ||
1260 | } | 1260 | } | ||
1261 | 1261 | | |||
1262 | // transforms the geometry of the moved window to a geometry on the desktop | 1262 | // transforms the geometry of the moved window to a geometry on the desktop | ||
1263 | // internal method only used when a window is dropped onto a desktop | 1263 | // internal method only used when a window is dropped onto a desktop | ||
1264 | QRectF DesktopGridEffect::moveGeometryToDesktop(int desktop) const | 1264 | QRectF DesktopGridEffect::moveGeometryToDesktop(int desktop) const | ||
1265 | { | 1265 | { | ||
1266 | QPointF point = unscalePos(m_windowMoveGeometry.topLeft() + cursorPos() - m_windowMoveStartPoint); | 1266 | QPointF point = unscalePos(m_windowMoveGeometry.topLeft() + cursorPos() - m_windowMoveStartPoint); | ||
1267 | const double scaleFactor = scale[ windowMove->screen()]; | 1267 | const double scaleFactor = scale[ windowMove->screen()]; | ||
▲ Show 20 Lines • Show All 251 Lines • Show Last 20 Lines |