Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 59 additions & 56 deletions src/session-widgets/lockcontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

#include "lockcontent.h"

#include "controlwidget.h"

Check warning on line 7 in src/session-widgets/lockcontent.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "controlwidget.h" not found.
#include "logowidget.h"

Check warning on line 8 in src/session-widgets/lockcontent.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "logowidget.h" not found.
#include "mfa_widget.h"
#include "modules_loader.h"
#include "popupwindow.h"

Check warning on line 10 in src/session-widgets/lockcontent.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "popupwindow.h" not found.
#include "sessionbasemodel.h"
#include "sfa_widget.h"
#include "shutdownwidget.h"
Expand All @@ -34,25 +33,10 @@

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)
{

}
Expand Down Expand Up @@ -143,7 +127,7 @@
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);

Expand Down Expand Up @@ -176,6 +160,7 @@
});
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);
Expand Down Expand Up @@ -212,12 +197,6 @@

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);
Expand Down Expand Up @@ -697,38 +676,7 @@
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<FloatingButton*>(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<QWidget*>()) {
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:
Expand All @@ -748,7 +696,6 @@
if ((watched == m_currentTray || isChild) && e->type() == QEvent::Enter) {
Q_EMIT qobject_cast<FloatingButton*>(m_currentTray)->requestHideTips();
} else if (watched != m_currentTray && !isChild && e->type() == QEvent::MouseButtonRelease) {
QMouseEvent *ev = static_cast<QMouseEvent *>(e);
if (!m_popWin->geometry().contains(this->mapFromGlobal(QCursor::pos()))) {
m_popWin->hide();
}
Expand Down Expand Up @@ -932,6 +879,62 @@
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<QWidget*>()) {
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()) {
Expand Down
47 changes: 24 additions & 23 deletions src/session-widgets/lockcontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<QWidget> m_virtualKB;
SessionBaseModel *m_model = nullptr;
ControlWidget *m_controlWidget = nullptr;
CenterTopWidget *m_centerTopWidget = nullptr;
ShutdownWidget *m_shutdownFrame = nullptr;
QPointer<QWidget> m_virtualKB = nullptr;
std::shared_ptr<User> m_user;
QList<QMetaObject::Connection> 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<QWidget> 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<QWidget> m_currentTray = nullptr;

bool m_isPANGUCpu = false;
bool m_MPRISEnable = false;
bool m_showMediaWidget = false;
bool m_hasResetPasswordDialog = false;
};

#endif // LOCKCONTENT_H
52 changes: 9 additions & 43 deletions src/widgets/controlwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "controlwidget.h"
#include "sessionbasemodel.h"

Check warning on line 6 in src/widgets/controlwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "sessionbasemodel.h" not found.
#include "kblayoutlistview.h"
#include "modules_loader.h"
#include "tipswidget.h"
#include "public_func.h"

Check warning on line 8 in src/widgets/controlwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "public_func.h" not found.
#include "plugin_manager.h"

Check warning on line 9 in src/widgets/controlwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "plugin_manager.h" not found.
#include "dconfig_helper.h"

Check warning on line 10 in src/widgets/controlwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dconfig_helper.h" not found.
#include "popupwindow.h"

#include <DFloatingButton>

Check warning on line 13 in src/widgets/controlwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DFloatingButton> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DArrowRectangle>

Check warning on line 14 in src/widgets/controlwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DArrowRectangle> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DPushButton>
#include <dimagebutton.h>
#include <DRegionMonitor>
Expand Down Expand Up @@ -88,10 +87,7 @@
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)
Expand Down Expand Up @@ -144,26 +140,6 @@
if (!languageList.isEmpty())
static_cast<QAbstractButton *>(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);
}

Expand Down Expand Up @@ -399,16 +375,16 @@
});

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));
}
});

Expand Down Expand Up @@ -636,14 +612,7 @@
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)
Expand Down Expand Up @@ -681,7 +650,8 @@
currentText = currentText.split("/").last();

static_cast<QAbstractButton *>(m_keyboardBtn)->setText(currentText.toUpper());
m_arrowRectWidget->hide();
// hide keyboard layout popup
Q_EMIT requestShowTrayModule(m_keyboardBtn, m_kbLayoutListView);
m_curUser->setKeyboardLayout(str);
}

Expand Down Expand Up @@ -722,10 +692,6 @@
}
}

if (watched == m_arrowRectWidget && event->type() == QEvent::Hide) {
emit notifyKeyboardLayoutHidden();
}

#else
Q_UNUSED(watched);
Q_UNUSED(event);
Expand Down
9 changes: 5 additions & 4 deletions src/widgets/controlwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
class SessionBaseModel;
class KBLayoutListView;
class TipsWidget;
class PopupWindow;

const int BlurRadius = 15;
const int BlurTransparency = 70;
Expand Down Expand Up @@ -106,9 +107,10 @@
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:

Check warning on line 113 in src/widgets/controlwidget.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
void addModule(TrayPlugin *module);
void removeModule(TrayPlugin *module);
void setVirtualKBVisible(bool visible);
Expand Down Expand Up @@ -157,12 +159,11 @@
QMap<QString, bool> 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<User> m_curUser;
QList<QMetaObject::Connection> m_connectionList;
bool m_onboardBtnVisible;
Expand Down
Loading