fix(fullscreen):bug#277721 控制面板提权界面未置顶

This commit is contained in:
yangmin100 2024-11-12 19:12:55 +08:00
parent ed75fe08de
commit 6d744cc196
4 changed files with 129 additions and 91 deletions

View File

@ -42,6 +42,7 @@ using namespace kdk;
FullScreenBackground::FullScreenBackground(QWidget *parent) : QWidget(parent) FullScreenBackground::FullScreenBackground(QWidget *parent) : QWidget(parent)
{ {
m_isWayland = QString(qgetenv("XDG_SESSION_TYPE")) == "wayland";
initUI(); initUI();
initConnections(); initConnections();
} }
@ -62,7 +63,17 @@ void FullScreenBackground::initMainWindow(
const bool &isSupportTableMode) const bool &isSupportTableMode)
{ {
if (!m_wndMain) { if (!m_wndMain) {
if (m_isWayland) {
m_wndMain = new MainWindow();
m_wndMain->setWindowFlags(windowFlags() | Qt::Tool | Qt::WindowStaysOnTopHint);
KWindowSystem::setState(m_wndMain->winId(), NET::State::KeepAbove | NET::State::SkipTaskbar);
} else {
m_wndMain = new MainWindow(this); m_wndMain = new MainWindow(this);
m_wndMain->setModal(true);
}
setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint & ~Qt::WindowMinimizeButtonHint);
m_wndMain->setWindowTitle(tr("Authentication"));
WindowManager::setSkipTaskBar(m_wndMain->windowHandle(), true);
m_wndMain->setIcon(strIconName); m_wndMain->setIcon(strIconName);
m_wndMain->setCurProject(isMavis); m_wndMain->setCurProject(isMavis);
m_wndMain->setHeader(strMsg); m_wndMain->setHeader(strMsg);
@ -70,6 +81,7 @@ void FullScreenBackground::initMainWindow(
m_wndMain->setEditInputMethod(isSupportTableMode); m_wndMain->setEditInputMethod(isSupportTableMode);
m_wndMain->setFixedSize(420, 337); m_wndMain->setFixedSize(420, 337);
/* /*
*
mainWindow->setDetails(subjectPid, callerPid, mainWindow->setDetails(subjectPid, callerPid,
actionDesc.actionId(), actionDesc.actionId(),
actionDesc.description(), actionDesc.description(),
@ -80,16 +92,22 @@ void FullScreenBackground::initMainWindow(
qDebug() << "auth dialog finished:" << nResult; qDebug() << "auth dialog finished:" << nResult;
}); });
} }
if (m_isWayland) {
hide();
} else {
show(); show();
} }
}
void FullScreenBackground::initUI() void FullScreenBackground::initUI()
{ {
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
// setWindowOpacity(0.25);
setAttribute(Qt::WA_TranslucentBackground);
setWindowTitle(tr("Authentication")); setWindowTitle(tr("Authentication"));
if (m_isWayland) {
setAttribute(Qt::WA_TranslucentBackground);
setGeometry(0, 0, 0, 0);
} else {
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
setWindowOpacity(0.25);
KWindowSystem::setState(winId(), NET::State::KeepAbove | NET::State::SkipTaskbar); KWindowSystem::setState(winId(), NET::State::KeepAbove | NET::State::SkipTaskbar);
WindowManager::setSkipTaskBar(this->windowHandle(), true); WindowManager::setSkipTaskBar(this->windowHandle(), true);
installEventFilter(this); installEventFilter(this);
@ -97,13 +115,7 @@ void FullScreenBackground::initUI()
if (!isSupportCompositing()) { if (!isSupportCompositing()) {
m_pixmapBackground = getBackground(); m_pixmapBackground = getBackground();
} }
QDesktopWidget *desktop = QApplication::desktop(); setGeometry(0, 0, 7680, 4320);
if (desktop) {
setGeometry(
desktop->geometry().x(),
desktop->geometry().y(),
desktop->geometry().width() + 1,
desktop->geometry().height() + 1);
} }
qDebug() << "Window geometry:" << geometry(); qDebug() << "Window geometry:" << geometry();
} }
@ -122,17 +134,23 @@ void FullScreenBackground::initConnections()
void FullScreenBackground::onScreenCountChanged(int) void FullScreenBackground::onScreenCountChanged(int)
{ {
qDebug() << "onScreenCountChanged----"; qDebug() << "onScreenCountChanged----";
if (m_isWayland) {
update();
moveToCursorScreen();
return;
}
QDesktopWidget *desktop = QApplication::desktop(); QDesktopWidget *desktop = QApplication::desktop();
if ((desktop->geometry().x() != 0 || desktop->geometry().y() != 0) && this->geometry().contains(desktop->geometry()) if ((desktop->geometry().x() != 0 || desktop->geometry().y() != 0) && this->geometry().contains(desktop->geometry())
&& (QApplication::screens().count() == 1)) { && (QApplication::screens().count() == 1)) {
return; return;
} }
if (desktop->geometry().height() > height() || desktop->geometry().width() > width()) {
setGeometry( setGeometry(
desktop->geometry().x(), desktop->geometry().x(),
desktop->geometry().y(), desktop->geometry().y(),
desktop->geometry().width() + 1, desktop->geometry().width() + 1,
desktop->geometry().height() + 1); desktop->geometry().height() + 1);
}
update(); update();
moveToCursorScreen(); moveToCursorScreen();
@ -154,16 +172,23 @@ void FullScreenBackground::onPrimaryScreenChanged()
void FullScreenBackground::onDesktopResized() void FullScreenBackground::onDesktopResized()
{ {
qDebug() << "onDesktopResized----"; qDebug() << "onDesktopResized----";
if (m_isWayland) {
update();
moveToCursorScreen();
return;
}
QDesktopWidget *desktop = QApplication::desktop(); QDesktopWidget *desktop = QApplication::desktop();
if ((desktop->geometry().x() != 0 || desktop->geometry().y() != 0) && this->geometry().contains(desktop->geometry()) if ((desktop->geometry().x() != 0 || desktop->geometry().y() != 0) && this->geometry().contains(desktop->geometry())
&& (QGuiApplication::screens().count() == 1)) { && (QGuiApplication::screens().count() == 1)) {
return; return;
} }
if (desktop->geometry().height() > height() || desktop->geometry().width() > width()) {
setGeometry( setGeometry(
desktop->geometry().x(), desktop->geometry().x(),
desktop->geometry().y(), desktop->geometry().y(),
desktop->geometry().width() + 1, desktop->geometry().width() + 1,
desktop->geometry().height() + 1); desktop->geometry().height() + 1);
}
update(); update();
moveToCursorScreen(); moveToCursorScreen();
@ -175,7 +200,9 @@ void FullScreenBackground::showDialog()
if (m_isFirstShow) { if (m_isFirstShow) {
m_isFirstShow = false; m_isFirstShow = false;
blockSomeShortCut(true); blockSomeShortCut(true);
if (!m_isWayland) {
show(); show();
}
if (m_wndMain) { if (m_wndMain) {
qDebug() << "DialogGeometry:" << m_wndMain->geometry(); qDebug() << "DialogGeometry:" << m_wndMain->geometry();
m_wndMain->show(); m_wndMain->show();
@ -200,9 +227,12 @@ void FullScreenBackground::closeDialog()
bool FullScreenBackground::isSupportCompositing() bool FullScreenBackground::isSupportCompositing()
{ {
if (QString(qgetenv("XDG_SESSION_TYPE")) == "wayland") {
return true;
}
QDBusInterface kwinCompositor( QDBusInterface kwinCompositor(
"org.ukui.KWin", "/Compositor", "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus()); "org.ukui.KWin", "/Compositor", "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus());
QDBusReply<QDBusVariant> sessionReply = kwinCompositor.call("Get", "org.ukui.kwin.Compositing", "compositingType"); QDBusReply<QDBusVariant> sessionReply = kwinCompositor.call("Get", "org.kde.kwin.Compositing", "compositingType");
if (!sessionReply.isValid()) { if (!sessionReply.isValid()) {
qWarning() << sessionReply.error(); qWarning() << sessionReply.error();
} else { } else {
@ -308,8 +338,18 @@ void FullScreenBackground::moveToScreen(QScreen *screen)
void FullScreenBackground::moveToCursorScreen() void FullScreenBackground::moveToCursorScreen()
{ {
bool isFoundScreen = false; bool isFoundScreen = false;
if (m_isWayland) {
QString strCurScreen = WindowManager::currentOutputName();
for (auto screen : QApplication::screens()) {
qDebug() << "Screen:" << screen->name() << "," << screen->geometry();
if (screen && screen->name() == strCurScreen) {
isFoundScreen = true;
moveToScreen(screen);
break;
}
}
} else {
QPoint cursor = QCursor::pos(); QPoint cursor = QCursor::pos();
// qDebug() << "CurCursor-------------:" << cursor << WindowManager::currentOutputName();
for (auto screen : QApplication::screens()) { for (auto screen : QApplication::screens()) {
qDebug() << "Screen:" << screen->name() << "," << screen->geometry(); qDebug() << "Screen:" << screen->name() << "," << screen->geometry();
if (screen && screen->geometry().contains(cursor)) { if (screen && screen->geometry().contains(cursor)) {
@ -318,6 +358,7 @@ void FullScreenBackground::moveToCursorScreen()
break; break;
} }
} }
}
if (!isFoundScreen) { if (!isFoundScreen) {
if (QApplication::primaryScreen()) { if (QApplication::primaryScreen()) {
moveToScreen(QApplication::primaryScreen()); moveToScreen(QApplication::primaryScreen());
@ -328,34 +369,28 @@ void FullScreenBackground::moveToCursorScreen()
void FullScreenBackground::paintEvent(QPaintEvent *event) void FullScreenBackground::paintEvent(QPaintEvent *event)
{ {
// for (auto screen : QApplication::screens()) { if (!m_isWayland) {
// QPainter painter(this); for (auto screen : QApplication::screens()) {
// if (!m_pixmapBackground.isNull()) { QPainter painter(this);
// painter.drawPixmap(screen->geometry(), m_pixmapBackground); if (!m_pixmapBackground.isNull()) {
// } painter.drawPixmap(screen->geometry(), m_pixmapBackground);
// QPainterPath path; }
// painter.setOpacity(0.25); }
// painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; }
// painter.setClipping(true);
// painter.setPen(Qt::transparent);
// path.addRect(screen->geometry());
// path.setFillRule(Qt::WindingFill);
// painter.setBrush(QColor(QPalette::Base));
// painter.setPen(Qt::transparent);
// painter.drawPath(path);
// }
return QWidget::paintEvent(event); return QWidget::paintEvent(event);
} }
void FullScreenBackground::closeEvent(QCloseEvent *event) void FullScreenBackground::closeEvent(QCloseEvent *event)
{ {
qDebug() << "FullScreenBackground::closeEvent"; qDebug() << "FullScreenBackground::closeEvent";
if (!m_isWayland) {
// 断开屏幕变化信号 // 断开屏幕变化信号
QDesktopWidget *desktop = QApplication::desktop(); QDesktopWidget *desktop = QApplication::desktop();
disconnect(desktop, &QDesktopWidget::resized, this, &FullScreenBackground::onDesktopResized); disconnect(desktop, &QDesktopWidget::resized, this, &FullScreenBackground::onDesktopResized);
disconnect(desktop, &QDesktopWidget::workAreaResized, this, &FullScreenBackground::onWorkAreaResized); disconnect(desktop, &QDesktopWidget::workAreaResized, this, &FullScreenBackground::onWorkAreaResized);
disconnect(desktop, &QDesktopWidget::primaryScreenChanged, this, &FullScreenBackground::onPrimaryScreenChanged); disconnect(desktop, &QDesktopWidget::primaryScreenChanged, this, &FullScreenBackground::onPrimaryScreenChanged);
disconnect(desktop, &QDesktopWidget::screenCountChanged, this, &FullScreenBackground::onScreenCountChanged); disconnect(desktop, &QDesktopWidget::screenCountChanged, this, &FullScreenBackground::onScreenCountChanged);
}
return QWidget::closeEvent(event); return QWidget::closeEvent(event);
} }
@ -434,9 +469,10 @@ void FullScreenBackground::blockSomeShortCut(bool isBlock /* = false*/)
"Window to Screen 4", // 窗口到屏幕 4 "Window to Screen 4", // 窗口到屏幕 4
}; };
sIsBlocked = isBlock; sIsBlocked = isBlock;
QDBusInterface kwinInterface("org.ukui.KWin", "/KWin", "org.ukui.KWin", QDBusConnection::sessionBus());
if (sIsBlocked) { if (sIsBlocked) {
if (!m_isWayland) {
// kwin shortcut // kwin shortcut
QDBusInterface kwinInterface("org.ukui.KWin", "/KWin", "org.kde.KWin", QDBusConnection::sessionBus());
for (QString strShortCut : listBlockShortCut) { for (QString strShortCut : listBlockShortCut) {
QDBusMessage blockMessage = kwinInterface.call("blockShortcut", strShortCut, true); QDBusMessage blockMessage = kwinInterface.call("blockShortcut", strShortCut, true);
if (blockMessage.type() == QDBusMessage::ErrorMessage) { if (blockMessage.type() == QDBusMessage::ErrorMessage) {
@ -444,12 +480,16 @@ void FullScreenBackground::blockSomeShortCut(bool isBlock /* = false*/)
break; break;
} }
} }
}
// usd shortcut // usd shortcut
if (!m_usdBlockShortCut) { if (!m_usdBlockShortCut) {
m_usdBlockShortCut = new USDBlockShortCut(this); m_usdBlockShortCut = new USDBlockShortCut(this);
} }
} else { } else {
if (!m_isWayland) {
// kwin shortcut // kwin shortcut
QDBusInterface kwinInterface("org.ukui.KWin", "/KWin", "org.kde.KWin", QDBusConnection::sessionBus());
for (QString strShortCut : listBlockShortCut) { for (QString strShortCut : listBlockShortCut) {
QDBusMessage blockMessage = kwinInterface.call("blockShortcut", strShortCut, false); QDBusMessage blockMessage = kwinInterface.call("blockShortcut", strShortCut, false);
if (blockMessage.type() == QDBusMessage::ErrorMessage) { if (blockMessage.type() == QDBusMessage::ErrorMessage) {
@ -457,6 +497,8 @@ void FullScreenBackground::blockSomeShortCut(bool isBlock /* = false*/)
break; break;
} }
} }
}
// usd shortcut // usd shortcut
if (m_usdBlockShortCut) { if (m_usdBlockShortCut) {
delete m_usdBlockShortCut; delete m_usdBlockShortCut;
@ -467,9 +509,5 @@ void FullScreenBackground::blockSomeShortCut(bool isBlock /* = false*/)
bool FullScreenBackground::eventFilter(QObject *obj, QEvent *event) bool FullScreenBackground::eventFilter(QObject *obj, QEvent *event)
{ {
if (event->type() == QEvent::Show || event->type() == QEvent::UpdateRequest) {
// WindowManager::setWindowLayer(this->windowHandle(), WindowLayer::ScreenLock);
WindowManager::setWindowRadius(this->windowHandle(), 0);
}
return QWidget::eventFilter(obj, event); return QWidget::eventFilter(obj, event);
} }

View File

@ -167,6 +167,7 @@ private:
QPixmap m_pixmapBackground; // 背景图 QPixmap m_pixmapBackground; // 背景图
bool m_isFirstShow = true; // 第一次显示才主动移动对话框居中 bool m_isFirstShow = true; // 第一次显示才主动移动对话框居中
USDBlockShortCut *m_usdBlockShortCut = nullptr; // usd禁启用快捷键实例 USDBlockShortCut *m_usdBlockShortCut = nullptr; // usd禁启用快捷键实例
bool m_isWayland = false;
}; };
#endif // FULLSCREENMANAGER_H #endif // FULLSCREENMANAGER_H

View File

@ -62,15 +62,8 @@ MainWindow::MainWindow(QWidget *parent)
, m_nCurLockMin(0) , m_nCurLockMin(0)
, isbioSuccess(false) , isbioSuccess(false)
{ {
setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint & ~Qt::WindowMinimizeButtonHint);
// setBackgroundRole(QPalette::Base);
// setAutoFillBackground(true);
setModal(true);
ui->setupUi(this); ui->setupUi(this);
mainLayout()->addLayout(ui->verticalLayout_2); mainLayout()->addLayout(ui->verticalLayout_2);
setWindowTitle(tr("Authentication"));
WindowManager::setSkipTaskBar(this->windowHandle(), true);
pam_tally_init(); // pam_tally_init(); //
@ -371,7 +364,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
} }
m_failMap.clear(); m_failMap.clear();
emit canceled(); emit canceled();
return kdk::KDialog::closeEvent(event); return kdk::KDialog::closeEvent(event);
} }
@ -478,7 +470,6 @@ void MainWindow::paintEvent(QPaintEvent *event)
// 绘制一个矩形 // 绘制一个矩形
p.setPen(Qt::red); p.setPen(Qt::red);
QRectF rect(0, 290, 20, 20);
} }
bool MainWindow::eventFilter(QObject *obj, QEvent *event) bool MainWindow::eventFilter(QObject *obj, QEvent *event)
@ -499,6 +490,12 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
return true; return true;
} }
} }
} else if (obj == this) {
if (event->type() == QEvent::Show || event->type() == QEvent::UpdateRequest) {
if (QString(qgetenv("XDG_SESSION_TYPE")) == "wayland") {
WindowManager::setWindowLayer(this->windowHandle(), WindowLayer::Switcher + 1);
}
}
} }
return kdk::KDialog::eventFilter(obj, event); return kdk::KDialog::eventFilter(obj, event);
} }

View File

@ -54,6 +54,8 @@ USDBlockShortCut::~USDBlockShortCut()
QStringList USDBlockShortCut::blockShortcuts() QStringList USDBlockShortCut::blockShortcuts()
{ {
QStringList listShortCut = { "WINDOWSWITCH_KEY" }; QStringList listShortCut = {
"WINDOWSWITCH_KEY", "WLCOM_SWITCH_WORKSPACE", "WLCOM_WINDOW_ACTION", "WLCOM_MAXIMIZED_VIEWS", "WLCOM_CTRL_VIEWS"
};
return listShortCut; return listShortCut;
} }