203 lines
6.8 KiB
Diff
203 lines
6.8 KiB
Diff
From c3472c9d50c5fb40f49d3de3d03d4d812bb48959 Mon Sep 17 00:00:00 2001
|
||
From: liuxinhao <liuxinhao@kylinsec.com.cn>
|
||
Date: Thu, 8 Dec 2022 10:56:20 +0800
|
||
Subject: [PATCH 5/6] fix(Locker VirtualKeyboard): unlock interface calls
|
||
onboard, and the onboard process cycle is consistent with the unlock
|
||
interface
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
- 解锁界面调用onboard,onboard进程周期和解锁界面一致,避免出现解锁后onboard进程不退出和kiran-screensaver同一生存周期的问题
|
||
---
|
||
lib/common-widgets/virtual-keyboard.cpp | 8 ++--
|
||
lib/common-widgets/virtual-keyboard.h | 8 ++--
|
||
screensaver-dialog/src/plugin.cpp | 8 ----
|
||
screensaver-dialog/src/screensaver-dialog.cpp | 37 +++++++++++--------
|
||
screensaver-dialog/src/screensaver-dialog.h | 4 ++
|
||
5 files changed, 33 insertions(+), 32 deletions(-)
|
||
|
||
diff --git a/lib/common-widgets/virtual-keyboard.cpp b/lib/common-widgets/virtual-keyboard.cpp
|
||
index a6921af..4e39e54 100644
|
||
--- a/lib/common-widgets/virtual-keyboard.cpp
|
||
+++ b/lib/common-widgets/virtual-keyboard.cpp
|
||
@@ -78,7 +78,7 @@ bool VirtualKeyboard::init(QWidget *parent)
|
||
}
|
||
|
||
xid = stdoutput.toULongLong();
|
||
-
|
||
+ KLOG_DEBUG() << "foreign virtual keyboard window id:" << xid;
|
||
foreignWindow = QWindow::fromWinId(xid);
|
||
foreignWindow->setFlag(Qt::ForeignWindow);
|
||
m_keyboardWidget = QWidget::createWindowContainer(foreignWindow, nullptr);
|
||
@@ -113,15 +113,15 @@ void VirtualKeyboard::showAdjustSize(QWidget *parent)
|
||
if (parent == nullptr)
|
||
{
|
||
KLOG_WARNING() << "VirtualKeyboard::showAdjustSize parent can't be nullptr";
|
||
+ return;
|
||
}
|
||
|
||
KLOG_DEBUG() << "VirtualKeyboard::showAdjustSize" << parent->objectName();
|
||
m_keyboardWidget->hide();
|
||
- QRect parentRect = parent->geometry();
|
||
m_keyboardWidget->setParent(parent);
|
||
|
||
+ QRect parentRect = parent->geometry();
|
||
QSize keyboardSize(parentRect.width()*ONBOARD_WIDTH_FACTOR,parentRect.height()*ONBOARD_HEIGHT_FACTOR);
|
||
-
|
||
m_keyboardWidget->resize(parentRect.width()*ONBOARD_WIDTH_FACTOR, parentRect.height()*ONBOARD_HEIGHT_FACTOR);
|
||
m_keyboardWidget->move((parentRect.width() - keyboardSize.width()) / 2, parentRect.height() - keyboardSize.height());
|
||
m_keyboardWidget->show();
|
||
@@ -170,4 +170,4 @@ VirtualKeyboard::VirtualKeyboard(QObject *parent)
|
||
|
||
void VirtualKeyboard::slotReadyReadStandardOutput()
|
||
{
|
||
-}
|
||
+}
|
||
\ No newline at end of file
|
||
diff --git a/lib/common-widgets/virtual-keyboard.h b/lib/common-widgets/virtual-keyboard.h
|
||
index 31ca7c7..72d8134 100644
|
||
--- a/lib/common-widgets/virtual-keyboard.h
|
||
+++ b/lib/common-widgets/virtual-keyboard.h
|
||
@@ -21,9 +21,11 @@ class VirtualKeyboard : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
- static VirtualKeyboard *instance();
|
||
+ explicit VirtualKeyboard(QObject *parent = nullptr);
|
||
~VirtualKeyboard();
|
||
|
||
+ static VirtualKeyboard *instance();
|
||
+
|
||
bool init(QWidget *parent = nullptr);
|
||
void hide();
|
||
bool isVisible();
|
||
@@ -34,13 +36,11 @@ public:
|
||
public slots:
|
||
void slot_finished(int exitCode, QProcess::ExitStatus exitStatus);
|
||
|
||
-private:
|
||
- explicit VirtualKeyboard(QObject *parent = nullptr);
|
||
-
|
||
private slots:
|
||
void slotReadyReadStandardOutput();
|
||
|
||
private:
|
||
QWidget * m_keyboardWidget;
|
||
QProcess *m_process;
|
||
+ QWidget *m_keyboardEmbed = nullptr;
|
||
};
|
||
diff --git a/screensaver-dialog/src/plugin.cpp b/screensaver-dialog/src/plugin.cpp
|
||
index 8699d3c..7c435de 100644
|
||
--- a/screensaver-dialog/src/plugin.cpp
|
||
+++ b/screensaver-dialog/src/plugin.cpp
|
||
@@ -46,14 +46,6 @@ int KSPlugin::init(Interface* ksInterface)
|
||
{
|
||
KLOG_WARNING() << "can't load kiran-screensaver-dialog translator";
|
||
}
|
||
-
|
||
-#ifdef VIRTUAL_KEYBOARD
|
||
- if( !VirtualKeyboard::instance()->init() )
|
||
- {
|
||
- KLOG_WARNING() << "init virtual keyboard failed!";
|
||
- }
|
||
-#endif
|
||
-
|
||
return 0;
|
||
}
|
||
|
||
diff --git a/screensaver-dialog/src/screensaver-dialog.cpp b/screensaver-dialog/src/screensaver-dialog.cpp
|
||
index 3ab7d19..2f1634e 100644
|
||
--- a/screensaver-dialog/src/screensaver-dialog.cpp
|
||
+++ b/screensaver-dialog/src/screensaver-dialog.cpp
|
||
@@ -101,7 +101,17 @@ ScreenSaverDialog::ScreenSaverDialog(Kiran::ScreenSaver::Interface* ksInterface,
|
||
|
||
ScreenSaverDialog::~ScreenSaverDialog()
|
||
{
|
||
- delete ui;
|
||
+#ifdef VIRTUAL_KEYBOARD
|
||
+ if( m_keyboard )
|
||
+ {
|
||
+ auto keyboardWidget = m_keyboard->getKeyboard();
|
||
+ if (m_keyboard->getKeyboard() && m_keyboard->getKeyboard()->parentWidget()==this)
|
||
+ {
|
||
+ m_keyboard->getKeyboard()->setParent(nullptr);
|
||
+ }
|
||
+ }
|
||
+#endif
|
||
+ delete ui;
|
||
}
|
||
|
||
QWidget *ScreenSaverDialog::get_widget_ptr()
|
||
@@ -274,17 +284,23 @@ void ScreenSaverDialog::initUI()
|
||
m_authProxy->respond(ui->promptEdit->getText());
|
||
});
|
||
|
||
+
|
||
#ifdef VIRTUAL_KEYBOARD
|
||
+ m_keyboard = new VirtualKeyboard(this);
|
||
+
|
||
+ if (!m_keyboard->init())
|
||
+ {
|
||
+ KLOG_WARNING() << "init virtual keyboard failed!";
|
||
+ }
|
||
connect(ui->btn_keyboard, &QToolButton::pressed, this, [this] {
|
||
- VirtualKeyboard *keyboard = VirtualKeyboard::instance();
|
||
- if (keyboard->isVisible())
|
||
+ if (m_keyboard->isVisible())
|
||
{
|
||
- keyboard->hide();
|
||
+ m_keyboard->hide();
|
||
}
|
||
else
|
||
{
|
||
//虚拟键盘通过传入的父窗口调整大小并进行显示
|
||
- keyboard->showAdjustSize(this);
|
||
+ m_keyboard->showAdjustSize(this);
|
||
}
|
||
this->window()->windowHandle()->setKeyboardGrabEnabled(true);
|
||
});
|
||
@@ -560,17 +576,6 @@ void ScreenSaverDialog::startAuth()
|
||
|
||
void ScreenSaverDialog::closeEvent(QCloseEvent *event)
|
||
{
|
||
-#ifdef VIRTUAL_KEYBOARD
|
||
- //在关闭时若虚拟键盘的副窗口设置为当前窗口的话,则更改父窗口,避免释放相关X资源导致onboard释放出错,导致onboard崩溃
|
||
- if (VirtualKeyboard::instance()->getKeyboard())
|
||
- {
|
||
- if (VirtualKeyboard::instance()->getKeyboard()->parentWidget() == this)
|
||
- {
|
||
- KLOG_DEBUG() << "keyboard reparent";
|
||
- VirtualKeyboard::instance()->getKeyboard()->setParent(nullptr);
|
||
- }
|
||
- }
|
||
-#endif
|
||
QWidget::closeEvent(event);
|
||
}
|
||
|
||
diff --git a/screensaver-dialog/src/screensaver-dialog.h b/screensaver-dialog/src/screensaver-dialog.h
|
||
index fe7a899..f166841 100644
|
||
--- a/screensaver-dialog/src/screensaver-dialog.h
|
||
+++ b/screensaver-dialog/src/screensaver-dialog.h
|
||
@@ -37,6 +37,7 @@ class Interface;
|
||
|
||
class QMenu;
|
||
class AuthProxy;
|
||
+class VirtualKeyboard;
|
||
class ScreenSaverDialog : public QWidget, public Kiran::ScreenSaver::LockerInterface
|
||
{
|
||
Q_OBJECT
|
||
@@ -112,6 +113,9 @@ private:
|
||
Kiran::AuthType m_authType = Kiran::AUTH_TYPE_PASSWD;
|
||
bool m_havePrompt = false;
|
||
QString m_userName;
|
||
+#ifdef VIRTUAL_KEYBOARD
|
||
+ VirtualKeyboard *m_keyboard = nullptr;
|
||
+#endif
|
||
};
|
||
|
||
#endif // WIDGET_H
|
||
--
|
||
2.33.0
|
||
|