mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 14:18:45 +00:00
refactor: onGrabCursor
This commit is contained in:
parent
41ef9e780a
commit
2e80a9e185
4 changed files with 32 additions and 20 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "avframeconvert.h"
|
#include "avframeconvert.h"
|
||||||
|
#include "mousetap/mousetap.h"
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#include "libavutil/imgutils.h"
|
#include "libavutil/imgutils.h"
|
||||||
|
@ -130,9 +131,10 @@ void Device::initSignals()
|
||||||
connect(this, &Device::screenshot, this, &Device::onScreenshot);
|
connect(this, &Device::screenshot, this, &Device::onScreenshot);
|
||||||
connect(this, &Device::showTouch, this, &Device::onShowTouch);
|
connect(this, &Device::showTouch, this, &Device::onShowTouch);
|
||||||
connect(this, &Device::setMainControl, this, &Device::onSetMainControl);
|
connect(this, &Device::setMainControl, this, &Device::onSetMainControl);
|
||||||
|
connect(this, &Device::grabCursor, this, &Device::onGrabCursor);
|
||||||
|
|
||||||
if (m_controller && m_videoForm) {
|
if (m_controller) {
|
||||||
connect(m_controller, &Controller::grabCursor, m_videoForm, &VideoForm::onGrabCursor);
|
connect(m_controller, &Controller::grabCursor, this, &Device::grabCursor);
|
||||||
}
|
}
|
||||||
if (m_controller) {
|
if (m_controller) {
|
||||||
connect(this, &Device::postGoBack, m_controller, &Controller::onPostGoBack);
|
connect(this, &Device::postGoBack, m_controller, &Controller::onPostGoBack);
|
||||||
|
@ -287,6 +289,15 @@ void Device::onSetMainControl(Device* device, bool mainControl)
|
||||||
m_mainControl = mainControl;
|
m_mainControl = mainControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::onGrabCursor(bool grab)
|
||||||
|
{
|
||||||
|
if (!m_videoForm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QRect rc = m_videoForm->getGrabCursorRect();
|
||||||
|
MouseTap::getInstance()->enableMouseEventTap(rc, grab);
|
||||||
|
}
|
||||||
|
|
||||||
bool Device::mainControl()
|
bool Device::mainControl()
|
||||||
{
|
{
|
||||||
return m_mainControl;
|
return m_mainControl;
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void deviceDisconnect(QString serial);
|
void deviceDisconnect(QString serial);
|
||||||
|
|
||||||
|
// tool bar
|
||||||
void switchFullScreen();
|
void switchFullScreen();
|
||||||
void postGoBack();
|
void postGoBack();
|
||||||
void postGoHome();
|
void postGoHome();
|
||||||
|
@ -58,27 +59,30 @@ signals:
|
||||||
void postVolumeDown();
|
void postVolumeDown();
|
||||||
void setScreenPowerMode(ControlMsg::ScreenPowerMode mode);
|
void setScreenPowerMode(ControlMsg::ScreenPowerMode mode);
|
||||||
void expandNotificationPanel();
|
void expandNotificationPanel();
|
||||||
void screenshot();
|
|
||||||
void showTouch(bool show);
|
|
||||||
void setMainControl(Device* device, bool mainControl);
|
|
||||||
|
|
||||||
void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize);
|
|
||||||
void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize);
|
|
||||||
void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize);
|
|
||||||
|
|
||||||
void postTurnOn();
|
void postTurnOn();
|
||||||
void postTextInput(QString& text);
|
void postTextInput(QString& text);
|
||||||
void requestDeviceClipboard();
|
void requestDeviceClipboard();
|
||||||
void setDeviceClipboard();
|
void setDeviceClipboard();
|
||||||
void clipboardPaste();
|
void clipboardPaste();
|
||||||
|
|
||||||
void pushFileRequest(const QString& serial, const QString& file, const QString& devicePath = "");
|
void pushFileRequest(const QString& serial, const QString& file, const QString& devicePath = "");
|
||||||
void installApkRequest(const QString& serial, const QString& apkFile);
|
void installApkRequest(const QString& serial, const QString& apkFile);
|
||||||
|
|
||||||
|
// key map
|
||||||
|
void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize);
|
||||||
|
void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize);
|
||||||
|
void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize);
|
||||||
|
|
||||||
|
// self connect signal and slots
|
||||||
|
void screenshot();
|
||||||
|
void showTouch(bool show);
|
||||||
|
void setMainControl(Device* device, bool mainControl);
|
||||||
|
void grabCursor(bool grab);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onScreenshot();
|
void onScreenshot();
|
||||||
void onShowTouch(bool show);
|
void onShowTouch(bool show);
|
||||||
void onSetMainControl(Device* device, bool mainControl);
|
void onSetMainControl(Device* device, bool mainControl);
|
||||||
|
void onGrabCursor(bool grab);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initSignals();
|
void initSignals();
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
#include "videoform.h"
|
#include "videoform.h"
|
||||||
#include "qyuvopenglwidget.h"
|
#include "qyuvopenglwidget.h"
|
||||||
#include "mousetap/mousetap.h"
|
|
||||||
#include "ui_videoform.h"
|
#include "ui_videoform.h"
|
||||||
#include "iconhelper.h"
|
#include "iconhelper.h"
|
||||||
#include "toolform.h"
|
#include "toolform.h"
|
||||||
|
@ -70,29 +69,27 @@ void VideoForm::initUI()
|
||||||
ui->keepRadioWidget->setMouseTracking(true);
|
ui->keepRadioWidget->setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoForm::onGrabCursor(bool grab)
|
QRect VideoForm::getGrabCursorRect()
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_WIN32)
|
|
||||||
QRect rc;
|
QRect rc;
|
||||||
rc = QRect(m_videoWidget->parentWidget()->mapToGlobal(m_videoWidget->pos())
|
#if defined(Q_OS_WIN32)
|
||||||
|
rc = QRect(m_videoWidget->mapToGlobal(m_videoWidget->pos())
|
||||||
, m_videoWidget->size());
|
, m_videoWidget->size());
|
||||||
// high dpi support
|
// high dpi support
|
||||||
rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio());
|
rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio());
|
||||||
rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio());
|
rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio());
|
||||||
MouseTap::getInstance()->enableMouseEventTap(rc, grab);
|
|
||||||
#elif defined(Q_OS_OSX)
|
#elif defined(Q_OS_OSX)
|
||||||
QRect rc = m_videoWidget->geometry();
|
rc = m_videoWidget->geometry();
|
||||||
rc.setTopLeft(m_videoWidget->mapToGlobal(rc.topLeft()));
|
rc.setTopLeft(m_videoWidget->mapToGlobal(rc.topLeft()));
|
||||||
rc.setBottomRight(m_videoWidget->mapToGlobal(rc.bottomRight()));
|
rc.setBottomRight(m_videoWidget->mapToGlobal(rc.bottomRight()));
|
||||||
rc.setX(rc.x() + 100);
|
rc.setX(rc.x() + 100);
|
||||||
rc.setY(rc.y() + 30);
|
rc.setY(rc.y() + 30);
|
||||||
rc.setWidth(rc.width() - 180);
|
rc.setWidth(rc.width() - 180);
|
||||||
rc.setHeight(rc.height() - 60);
|
rc.setHeight(rc.height() - 60);
|
||||||
|
|
||||||
MouseTap::getInstance()->enableMouseEventTap(rc, grab);
|
|
||||||
#else
|
#else
|
||||||
Q_UNUSED(grab)
|
Q_UNUSED(grab)
|
||||||
#endif
|
#endif
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoForm::updateRender(const AVFrame *frame)
|
void VideoForm::updateRender(const AVFrame *frame)
|
||||||
|
|
|
@ -24,9 +24,9 @@ public:
|
||||||
void updateShowSize(const QSize &newSize);
|
void updateShowSize(const QSize &newSize);
|
||||||
void updateRender(const AVFrame *frame);
|
void updateRender(const AVFrame *frame);
|
||||||
void setDevice(Device *device);
|
void setDevice(Device *device);
|
||||||
|
QRect getGrabCursorRect();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onGrabCursor(bool grab);
|
|
||||||
void onSwitchFullScreen();
|
void onSwitchFullScreen();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue