diff --git a/src/session-widgets/lockcontent.cpp b/src/session-widgets/lockcontent.cpp index 31a73ec3..65adcd2a 100644 --- a/src/session-widgets/lockcontent.cpp +++ b/src/session-widgets/lockcontent.cpp @@ -7,7 +7,6 @@ #include "controlwidget.h" #include "logowidget.h" #include "mfa_widget.h" -#include "modules_loader.h" #include "popupwindow.h" #include "sessionbasemodel.h" #include "sfa_widget.h" @@ -34,25 +33,10 @@ DCORE_USE_NAMESPACE LockContent::LockContent(QWidget *parent) : SessionBaseWindow(parent) - , m_model(nullptr) - , m_controlWidget(nullptr) - , m_centerTopWidget(nullptr) - , m_virtualKB(nullptr) , m_wmInter(new com::deepin::wm("com.deepin.wm", "/com/deepin/wm", QDBusConnection::sessionBus(), this)) - , m_sfaWidget(nullptr) - , m_mfaWidget(nullptr) - , m_authWidget(nullptr) - , m_fmaWidget(nullptr) - , m_userListWidget(nullptr) , m_localServer(new QLocalServer(this)) , m_currentModeStatus(SessionBaseModel::ModeStatus::NoStatus) - , m_initialized(false) - , m_isUserSwitchVisible(false) - , m_popWin(nullptr) - , m_isPANGUCpu(false) - , m_MPRISEnable(false) , m_showMediaWidget(DConfigHelper::instance()->getConfig(SHOW_MEDIA_WIDGET, false).toBool()) - , m_hasResetPasswordDialog(false) { } @@ -143,7 +127,7 @@ void LockContent::initUI() m_logoWidget->setAccessibleName("LogoWidget"); setLeftBottomWidget(m_logoWidget); - m_controlWidget = new ControlWidget(m_model); + m_controlWidget = new ControlWidget(m_model, this); m_controlWidget->setAccessibleName("ControlWidget"); setRightBottomWidget(m_controlWidget); @@ -176,6 +160,7 @@ void LockContent::initConnections() }); connect(m_controlWidget, &ControlWidget::requestSwitchVirtualKB, this, &LockContent::toggleVirtualKB); connect(m_controlWidget, &ControlWidget::requestShowModule, this, &LockContent::showModule); + connect(m_controlWidget, &ControlWidget::requestShowTrayModule, this, &LockContent::showTrayPopup); // 刷新背景单独与onStatusChanged信号连接,避免在showEvent事件时调用onStatusChanged而重复刷新背景,减少刷新次数 connect(m_model, &SessionBaseModel::onStatusChanged, this, &LockContent::onStatusChanged); @@ -212,12 +197,6 @@ void LockContent::initConnections() connect(m_wmInter, &com::deepin::wm::WorkspaceSwitched, this, &LockContent::currentWorkspaceChanged); connect(m_localServer, &QLocalServer::newConnection, this, &LockContent::onNewConnection); - connect(m_controlWidget, &ControlWidget::notifyKeyboardLayoutHidden, this, [this]{ - if (!m_model->isUseWayland() && isVisible() && window()->windowHandle()) { - qCDebug(DDE_SHELL) << "Grab keyboard after keyboard layout hidden"; - window()->windowHandle()->setKeyboardGrabEnabled(true); - } - }); connect(m_model, &SessionBaseModel::showUserList, this, &LockContent::showUserList); connect(m_model, &SessionBaseModel::showLockScreen, this, &LockContent::showLockScreen); @@ -697,38 +676,7 @@ void LockContent::showModule(const QString &name, const bool callShowForce) qCWarning(DDE_SHELL) << "TrayButton or plugin`s content is null"; return; } - - if (!m_popWin) { - m_popWin = new PopupWindow(this); - connect(m_model, &SessionBaseModel::visibleChanged, this, [this] (const bool visible) { - if (!visible) { - m_popWin->hide(); - } - }); - connect(m_popWin, &PopupWindow::visibleChanged, this, [this] (bool visible) { - m_controlWidget->setCanShowMenu(!visible); - }); - connect(qobject_cast(m_currentTray), &FloatingButton::buttonHide, m_popWin, &PopupWindow::hide); - connect(this, &LockContent::parentChanged, this, [this] { - if (m_popWin && m_popWin->isVisible()) { - const QPoint &point = mapFromGlobal(m_currentTray->mapToGlobal(QPoint(m_currentTray->size().width() / 2, 0))); - m_popWin->show(point); - } - }); - } - - // 隐藏后需要removeEventFilter,后期优化 - for (auto child : this->findChildren()) { - child->removeEventFilter(this); - child->installEventFilter(this); - } - - if (!m_popWin->getContent() || m_popWin->getContent() != plugin->content()) - m_popWin->setContent(plugin->content()); - const QPoint &point = mapFromGlobal(m_currentTray->mapToGlobal(QPoint(m_currentTray->size().width() / 2, 0))); - // 插件图标不显示,窗口不显示 - if (m_currentTray->isVisible()) - callShowForce ? m_popWin->show(point) : m_popWin->toggle(point); + showTrayPopup(m_currentTray, plugin->content()); break; } default: @@ -748,7 +696,6 @@ bool LockContent::eventFilter(QObject *watched, QEvent *e) if ((watched == m_currentTray || isChild) && e->type() == QEvent::Enter) { Q_EMIT qobject_cast(m_currentTray)->requestHideTips(); } else if (watched != m_currentTray && !isChild && e->type() == QEvent::MouseButtonRelease) { - QMouseEvent *ev = static_cast(e); if (!m_popWin->geometry().contains(this->mapFromGlobal(QCursor::pos()))) { m_popWin->hide(); } @@ -932,6 +879,62 @@ void LockContent::refreshLayout(SessionBaseModel::ModeStatus status) setBottomFrameVisible(status != SessionBaseModel::ModeStatus::ShutDownMode); } +void LockContent::showTrayPopup(QWidget *trayWidget, QWidget *contentWidget, const bool callShowForce) +{ + if (!trayWidget || !contentWidget) { + return; + } + + if (!m_popWin) { + m_popWin = new PopupWindow(this); + connect(m_model, &SessionBaseModel::visibleChanged, this, [this] (const bool visible) { + if (!visible) { + m_popWin->hide(); + } + }); + connect(m_popWin, &PopupWindow::visibleChanged, this, [this] (bool visible) { + m_controlWidget->setCanShowMenu(!visible); + // BUG-134087, tray popup窗口隐藏后,锁屏界面需要重新抓取键盘 + if (!visible && !m_model->isUseWayland() && isVisible() && window()->windowHandle()) { + qCDebug(DDE_SHELL) << "Grab keyboard after keyboard layout hidden"; + window()->windowHandle()->setKeyboardGrabEnabled(true); + } + }); + + connect(this, &LockContent::parentChanged, this, [this] { + if (m_popWin && m_popWin->isVisible()) { + const QPoint &point = mapFromGlobal(m_currentTray->mapToGlobal(QPoint(m_currentTray->size().width() / 2, 0))); + m_popWin->show(point); + } + }); + + // for BUG-256133 + connect(m_model, &SessionBaseModel::onStatusChanged, this, [this] (SessionBaseModel::ModeStatus status) { + if (status != SessionBaseModel::ModeStatus::PasswordMode) { + m_popWin->hide(); + } + }); + } + + m_currentTray = trayWidget; + + // 隐藏后需要removeEventFilter,后期优化 + for (auto child : this->findChildren()) { + child->removeEventFilter(this); + child->installEventFilter(this); + } + + if (!m_popWin->getContent() || m_popWin->getContent() != contentWidget) + m_popWin->setContent(contentWidget); + + const QPoint point = mapFromGlobal(m_currentTray->mapToGlobal(QPoint(m_currentTray->size().width() / 2, 0))); + // 插件图标不显示,窗口不显示 + if (m_currentTray->isVisible()) { + m_popWin->move(point.x(), point.y()); + callShowForce ? m_popWin->show(point) : m_popWin->toggle(point); + } +} + void LockContent::keyPressEvent(QKeyEvent *event) { switch (event->key()) { diff --git a/src/session-widgets/lockcontent.h b/src/session-widgets/lockcontent.h index 32932ec5..b25ec2b6 100644 --- a/src/session-widgets/lockcontent.h +++ b/src/session-widgets/lockcontent.h @@ -92,6 +92,7 @@ public slots: void updateWallpaper(const QString &path); void refreshBackground(SessionBaseModel::ModeStatus status); void refreshLayout(SessionBaseModel::ModeStatus status); + void showTrayPopup(QWidget *trayWidget, QWidget *contentWidget, const bool callShowForce = false); void initUI(); void initConnections(); @@ -102,36 +103,36 @@ public slots: void enableSystemShortcut(const QStringList &shortcuts, bool enabled, bool isPersistent); protected: - SessionBaseModel *m_model; - ControlWidget *m_controlWidget; - CenterTopWidget *m_centerTopWidget; - ShutdownWidget *m_shutdownFrame; - QPointer m_virtualKB; + SessionBaseModel *m_model = nullptr; + ControlWidget *m_controlWidget = nullptr; + CenterTopWidget *m_centerTopWidget = nullptr; + ShutdownWidget *m_shutdownFrame = nullptr; + QPointer m_virtualKB = nullptr; std::shared_ptr m_user; QList m_currentUserConnects; - LogoWidget *m_logoWidget; + LogoWidget *m_logoWidget = nullptr; MediaWidget *m_mediaWidget = nullptr; - com::deepin::wm *m_wmInter; - QWidget *m_loginWidget; + com::deepin::wm *m_wmInter = nullptr; + QWidget *m_loginWidget = nullptr; - SFAWidget *m_sfaWidget; - MFAWidget *m_mfaWidget; - AuthWidget *m_authWidget; - FullManagedAuthWidget *m_fmaWidget; - UserFrameList *m_userListWidget; + SFAWidget *m_sfaWidget = nullptr; + MFAWidget *m_mfaWidget = nullptr; + AuthWidget *m_authWidget = nullptr; + FullManagedAuthWidget *m_fmaWidget = nullptr; + UserFrameList *m_userListWidget = nullptr; int m_failures = 0; - QLocalServer *m_localServer; + QLocalServer *m_localServer = nullptr; SessionBaseModel::ModeStatus m_currentModeStatus; - bool m_initialized; - bool m_isUserSwitchVisible; - PopupWindow *m_popWin; - QPointer m_currentTray; - - bool m_isPANGUCpu; - bool m_MPRISEnable; - bool m_showMediaWidget; - bool m_hasResetPasswordDialog; + bool m_initialized = false; + bool m_isUserSwitchVisible = false; + PopupWindow *m_popWin = nullptr; + QPointer m_currentTray = nullptr; + + bool m_isPANGUCpu = false; + bool m_MPRISEnable = false; + bool m_showMediaWidget = false; + bool m_hasResetPasswordDialog = false; }; #endif // LOCKCONTENT_H diff --git a/src/widgets/controlwidget.cpp b/src/widgets/controlwidget.cpp index 64ee5d42..8253d725 100644 --- a/src/widgets/controlwidget.cpp +++ b/src/widgets/controlwidget.cpp @@ -5,11 +5,10 @@ #include "controlwidget.h" #include "sessionbasemodel.h" #include "kblayoutlistview.h" -#include "modules_loader.h" -#include "tipswidget.h" #include "public_func.h" #include "plugin_manager.h" #include "dconfig_helper.h" +#include "popupwindow.h" #include #include @@ -88,10 +87,7 @@ void FloatingButton::paintEvent(QPaintEvent *event) ControlWidget::ControlWidget(const SessionBaseModel *model, QWidget *parent) : QWidget(parent) , m_contextMenu(new QMenu(this)) - , m_tipsWidget(new TipsWidget()) - , m_arrowRectWidget(new DArrowRectangle(DArrowRectangle::ArrowBottom, this)) - , m_kbLayoutListView(nullptr) - , m_keyboardBtn(nullptr) + , m_tipsWidget(new PopupWindow(parent)) , m_onboardBtnVisible(true) , m_doGrabKeyboard(true) , m_canShowMenu(true) @@ -144,26 +140,6 @@ void ControlWidget::initKeyboardLayoutList() if (!languageList.isEmpty()) static_cast(m_keyboardBtn)->setText(languageList.at(0).toUpper()); - // 无特效模式时,让窗口圆角 - m_arrowRectWidget->setProperty("_d_radius_force", true); - m_arrowRectWidget->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::WindowStaysOnTopHint); - m_arrowRectWidget->setMargin(0); - m_arrowRectWidget->setShadowBlurRadius(20); - m_arrowRectWidget->setRadius(6); - m_arrowRectWidget->setShadowYOffset(2); - m_arrowRectWidget->setShadowXOffset(0); - m_arrowRectWidget->setArrowWidth(18); - m_arrowRectWidget->setArrowHeight(10); - m_arrowRectWidget->setMinimumWidth(DDESESSIONCC::KEYBOARD_LAYOUT_WIDTH); - m_arrowRectWidget->setMaximumSize(DDESESSIONCC::KEYBOARD_LAYOUT_WIDTH, DDESESSIONCC::LAYOUT_BUTTON_HEIGHT * 7); - m_arrowRectWidget->setFocusPolicy(Qt::NoFocus); - m_arrowRectWidget->setBackgroundColor(QColor(235, 235, 235, int(0.05 * 255))); - m_arrowRectWidget->installEventFilter(this); - - QPalette pal = m_arrowRectWidget->palette(); - pal.setColor(DPalette::Inactive, DPalette::Base, QColor(235, 235, 235, int(0.05 * 255))); - setPalette(pal); - connect(m_kbLayoutListView, &KBLayoutListView::itemClicked, this, &ControlWidget::onItemClicked); } @@ -399,16 +375,16 @@ void ControlWidget::addModule(TrayPlugin *trayModule) }); connect(button, &FloatingButton::requestShowTips, this, [=] { - if (trayModule->itemTipsWidget() && !trayModule->content()->isVisible()) { + if (trayModule->itemTipsWidget() && !trayModule->content()->isVisible() && topLevelWidget()) { m_tipsWidget->setContent(trayModule->itemTipsWidget()); // 因为密码框需要一直获取焦点,会导致TipsWidget在间隙时间内的Visible变为false // DArrowRectangle::show中当Visible为false时会activateWindow,抢占密码框焦点 // 所以这里手动设置visible为true - int x = mapToGlobal(button->pos()).x() + button->width() / 2; - int y = mapToGlobal(button->pos()).y(); + int x = mapTo(topLevelWidget(), button->pos()).x() + button->width() / 2; + int y = mapTo(topLevelWidget(), button->pos()).y(); m_tipsWidget->move(x, y); m_tipsWidget->setVisible(true); - m_tipsWidget->show(x, y); + m_tipsWidget->show(QPoint(x, y)); } }); @@ -636,14 +612,7 @@ void ControlWidget::setKBLayoutVisible() if (!layoutButton) return; - if (!m_arrowRectWidget->getContent()) { - m_arrowRectWidget->setContent(m_kbLayoutListView); - } - m_arrowRectWidget->resize(m_kbLayoutListView->size() + QSize(0, 10)); - - QPoint pos = QPoint(mapToGlobal(layoutButton->pos()).x() + layoutButton->width() / 2, mapToGlobal(layoutButton->pos()).y()); - m_arrowRectWidget->move(pos.x(), pos.y()); - m_arrowRectWidget->setVisible(!m_arrowRectWidget->isVisible()); + Q_EMIT requestShowTrayModule(layoutButton, m_kbLayoutListView); } void ControlWidget::setKeyboardType(const QString &str) @@ -681,7 +650,8 @@ void ControlWidget::onItemClicked(const QString &str) currentText = currentText.split("/").last(); static_cast(m_keyboardBtn)->setText(currentText.toUpper()); - m_arrowRectWidget->hide(); + // hide keyboard layout popup + Q_EMIT requestShowTrayModule(m_keyboardBtn, m_kbLayoutListView); m_curUser->setKeyboardLayout(str); } @@ -722,10 +692,6 @@ bool ControlWidget::eventFilter(QObject *watched, QEvent *event) } } - if (watched == m_arrowRectWidget && event->type() == QEvent::Hide) { - emit notifyKeyboardLayoutHidden(); - } - #else Q_UNUSED(watched); Q_UNUSED(event); diff --git a/src/widgets/controlwidget.h b/src/widgets/controlwidget.h index 7420d858..2edb15c9 100644 --- a/src/widgets/controlwidget.h +++ b/src/widgets/controlwidget.h @@ -38,6 +38,7 @@ class QMenu; class SessionBaseModel; class KBLayoutListView; class TipsWidget; +class PopupWindow; const int BlurRadius = 15; const int BlurTransparency = 70; @@ -106,6 +107,7 @@ class ControlWidget : public QWidget void requestSwitchVirtualKB(); void requestKeyboardLayout(const QPoint &pos); void requestShowModule(const QString &name, const bool callShowForce = false); + void requestShowTrayModule(QWidget *trayWidget, QWidget *contentWidget, const bool callShowForce = false); void notifyKeyboardLayoutHidden(); public slots: @@ -157,12 +159,11 @@ public slots: QMap m_modulesVisible; QMenu *m_contextMenu; - TipsWidget *m_tipsWidget; + PopupWindow *m_tipsWidget = nullptr; const SessionBaseModel *m_model; - DArrowRectangle *m_arrowRectWidget; - KBLayoutListView *m_kbLayoutListView; // 键盘布局列表 - DFloatingButton *m_keyboardBtn; // 键盘布局按钮 + KBLayoutListView *m_kbLayoutListView = nullptr; // 键盘布局列表 + FloatingButton *m_keyboardBtn = nullptr; // 键盘布局按钮 std::shared_ptr m_curUser; QList m_connectionList; bool m_onboardBtnVisible;