fix: clipboard bug

This commit is contained in:
Barry 2022-01-16 21:57:44 +08:00
parent 228f3e8463
commit acf7ef7077
8 changed files with 70 additions and 18 deletions

View file

@ -65,9 +65,10 @@ bool Controller::isCurrentCustomKeymap()
return m_inputConvert->isCurrentCustomKeymap();
}
void Controller::onPostBackOrScreenOn()
void Controller::onPostBackOrScreenOn(bool down)
{
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON);
controlMsg->setBackOrScreenOnData(down);
if (!controlMsg) {
return;
}
@ -128,9 +129,9 @@ void Controller::onExpandNotificationPanel()
postControlMsg(controlMsg);
}
void Controller::onCollapseNotificationPanel()
void Controller::onCollapsePanel()
{
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_NOTIFICATION_PANEL);
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_PANELS);
if (!controlMsg) {
return;
}
@ -146,6 +147,17 @@ void Controller::onRequestDeviceClipboard()
postControlMsg(controlMsg);
}
void Controller::onGetDeviceClipboard(bool cut)
{
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD);
if (!controlMsg) {
return;
}
ControlMsg::GetClipboardCopyKey copyKey = cut ? ControlMsg::GCCK_CUT : ControlMsg::GCCK_COPY;
controlMsg->setGetClipboardMsgData(copyKey);
postControlMsg(controlMsg);
}
void Controller::onSetDeviceClipboard(bool pause)
{
QClipboard *board = QApplication::clipboard();

View file

@ -34,7 +34,7 @@ public slots:
void onCopy();
void onCut();
void onExpandNotificationPanel();
void onCollapseNotificationPanel();
void onCollapsePanel();
void onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode);
// for input convert
@ -43,8 +43,10 @@ public slots:
void onKeyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize);
// turn the screen on if it was off, press BACK otherwise
void onPostBackOrScreenOn();
// If the screen is off, it is turned on only on down
void onPostBackOrScreenOn(bool down);
void onRequestDeviceClipboard();
void onGetDeviceClipboard(bool cut = false);
void onSetDeviceClipboard(bool pause = true);
void onClipboardPaste();
void onPostTextInput(QString &text);

View file

@ -56,6 +56,11 @@ void ControlMsg::setInjectScrollMsgData(QRect position, qint32 hScroll, qint32 v
m_data.injectScroll.vScroll = vScroll;
}
void ControlMsg::setGetClipboardMsgData(ControlMsg::GetClipboardCopyKey copyKey)
{
m_data.getClipboard.copyKey = copyKey;
}
void ControlMsg::setSetClipboardMsgData(QString &text, bool paste)
{
if (text.isEmpty()) {
@ -70,6 +75,7 @@ void ControlMsg::setSetClipboardMsgData(QString &text, bool paste)
memcpy(m_data.setClipboard.text, tmp.data(), tmp.length());
m_data.setClipboard.text[tmp.length()] = '\0';
m_data.setClipboard.paste = paste;
m_data.setClipboard.sequence = 0;
}
void ControlMsg::setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode)
@ -77,6 +83,11 @@ void ControlMsg::setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode)
m_data.setScreenPowerMode.mode = mode;
}
void ControlMsg::setBackOrScreenOnData(bool down)
{
m_data.backOrScreenOn.action = down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP;
}
void ControlMsg::writePosition(QBuffer &buffer, const QRect &value)
{
BufferUtil::write32(buffer, value.left());
@ -126,7 +137,13 @@ QByteArray ControlMsg::serializeData()
BufferUtil::write32(buffer, m_data.injectScroll.hScroll);
BufferUtil::write32(buffer, m_data.injectScroll.vScroll);
break;
case CMT_BACK_OR_SCREEN_ON:
buffer.putChar(m_data.backOrScreenOn.action);
break;
case CMT_GET_CLIPBOARD:
buffer.putChar(m_data.getClipboard.copyKey);
case CMT_SET_CLIPBOARD:
BufferUtil::write64(buffer, m_data.setClipboard.sequence);
buffer.putChar(!!m_data.setClipboard.paste);
BufferUtil::write32(buffer, static_cast<quint32>(strlen(m_data.setClipboard.text)));
buffer.write(m_data.setClipboard.text, strlen(m_data.setClipboard.text));
@ -134,10 +151,10 @@ QByteArray ControlMsg::serializeData()
case CMT_SET_SCREEN_POWER_MODE:
buffer.putChar(m_data.setScreenPowerMode.mode);
break;
case CMT_BACK_OR_SCREEN_ON:
case CMT_EXPAND_NOTIFICATION_PANEL:
case CMT_COLLAPSE_NOTIFICATION_PANEL:
case CMT_GET_CLIPBOARD:
case CMT_EXPAND_SETTINGS_PANEL:
case CMT_COLLAPSE_PANELS:
case CMT_ROTATE_DEVICE:
break;
default:
qDebug() << "Unknown event type:" << m_data.type;

View file

@ -17,6 +17,7 @@
(CONTROL_MSG_MAX_SIZE - 6)
#define POINTER_ID_MOUSE static_cast<quint64>(-1)
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2)
// ControlMsg
class ControlMsg : public QScrcpyEvent
@ -31,10 +32,12 @@ public:
CMT_INJECT_SCROLL,
CMT_BACK_OR_SCREEN_ON,
CMT_EXPAND_NOTIFICATION_PANEL,
CMT_COLLAPSE_NOTIFICATION_PANEL,
CMT_EXPAND_SETTINGS_PANEL,
CMT_COLLAPSE_PANELS,
CMT_GET_CLIPBOARD,
CMT_SET_CLIPBOARD,
CMT_SET_SCREEN_POWER_MODE
CMT_SET_SCREEN_POWER_MODE,
CMT_ROTATE_DEVICE
};
enum ScreenPowerMode
@ -44,6 +47,12 @@ public:
SPM_NORMAL = 2,
};
enum GetClipboardCopyKey {
GCCK_NONE,
GCCK_COPY,
GCCK_CUT,
};
ControlMsg(ControlMsgType controlMsgType);
virtual ~ControlMsg();
@ -54,8 +63,10 @@ public:
// position action动作对应的位置
void setInjectTouchMsgData(quint64 id, AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position, float pressure);
void setInjectScrollMsgData(QRect position, qint32 hScroll, qint32 vScroll);
void setGetClipboardMsgData(ControlMsg::GetClipboardCopyKey copyKey);
void setSetClipboardMsgData(QString &text, bool paste);
void setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode);
void setBackOrScreenOnData(bool down);
QByteArray serializeData();
@ -96,6 +107,16 @@ private:
} injectScroll;
struct
{
AndroidKeyeventAction action; // action for the BACK key
// screen may only be turned on on ACTION_DOWN
} backOrScreenOn;
struct
{
enum GetClipboardCopyKey copyKey;
} getClipboard;
struct
{
uint64_t sequence = 0;
char *text = Q_NULLPTR;
bool paste = true;
} setClipboard;

View file

@ -155,7 +155,7 @@ void Device::initSignals()
connect(this, &Device::postCut, m_controller, &Controller::onCut);
connect(this, &Device::setScreenPowerMode, m_controller, &Controller::onSetScreenPowerMode);
connect(this, &Device::expandNotificationPanel, m_controller, &Controller::onExpandNotificationPanel);
connect(this, &Device::collapseNotificationPanel, m_controller, &Controller::onCollapseNotificationPanel);
connect(this, &Device::collapsePanel, m_controller, &Controller::onCollapsePanel);
connect(this, &Device::mouseEvent, m_controller, &Controller::onMouseEvent);
connect(this, &Device::wheelEvent, m_controller, &Controller::onWheelEvent);
connect(this, &Device::keyEvent, m_controller, &Controller::onKeyEvent);

View file

@ -76,8 +76,8 @@ signals:
void postCut();
void setScreenPowerMode(ControlMsg::ScreenPowerMode mode);
void expandNotificationPanel();
void collapseNotificationPanel();
void postBackOrScreenOn();
void collapsePanel();
void postBackOrScreenOn(bool down);
void postTextInput(QString &text);
void requestDeviceClipboard();
void setDeviceClipboard(bool pause = true);

View file

@ -295,14 +295,14 @@ void VideoForm::installShortcut()
emit m_device->expandNotificationPanel();
});
// collapseNotificationPanel
// collapsePanel
shortcut = new QShortcut(QKeySequence("Ctrl+Shift+n"), this);
shortcut->setAutoRepeat(false);
connect(shortcut, &QShortcut::activated, this, [this]() {
if (!m_device) {
return;
}
emit m_device->collapseNotificationPanel();
emit m_device->collapsePanel();
});
// copy
@ -613,7 +613,7 @@ void VideoForm::mouseDoubleClickEvent(QMouseEvent *event)
}
if (event->button() == Qt::RightButton && m_device && !m_device->isCurrentCustomKeymap()) {
emit m_device->postBackOrScreenOn();
emit m_device->postBackOrScreenOn(event->type() == QEvent::MouseButtonPress);
}
if (m_videoWidget->geometry().contains(event->pos())) {

View file

@ -130,7 +130,7 @@ void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool ins
connect(host, &Device::postVolumeDown, client, &Device::postVolumeDown);
connect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode);
connect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel);
connect(host, &Device::collapseNotificationPanel, client, &Device::collapseNotificationPanel);
connect(host, &Device::collapsePanel, client, &Device::collapsePanel);
connect(host, &Device::postBackOrScreenOn, client, &Device::postBackOrScreenOn);
connect(host, &Device::postTextInput, client, &Device::postTextInput);
connect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard);
@ -149,7 +149,7 @@ void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool ins
disconnect(host, &Device::postVolumeDown, client, &Device::postVolumeDown);
disconnect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode);
disconnect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel);
disconnect(host, &Device::collapseNotificationPanel, client, &Device::collapseNotificationPanel);
disconnect(host, &Device::collapsePanel, client, &Device::collapsePanel);
disconnect(host, &Device::postBackOrScreenOn, client, &Device::postBackOrScreenOn);
disconnect(host, &Device::postTextInput, client, &Device::postTextInput);
disconnect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard);