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