mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-21 20:15:04 +00:00
feat: add mac frameless window
This commit is contained in:
parent
a46693a931
commit
9b4484a599
5 changed files with 87 additions and 3 deletions
|
@ -1,10 +1,11 @@
|
|||
import QtQuick 2.12
|
||||
import QtQuick.Window 2.12
|
||||
import barry.uibase 1.0
|
||||
|
||||
Window {
|
||||
id: root
|
||||
visible: true
|
||||
flags: Qt.Window | Qt.WindowMaximizeButtonHint | (Qt.platform.os == "windows" ? Qt.FramelessWindowHint : 0)
|
||||
flags: Qt.Window | (Qt.platform.os == "windows" ? (Qt.FramelessWindowHint | Qt.WindowMaximizeButtonHint) : 0)
|
||||
width: 800
|
||||
height: 600
|
||||
color: "transparent"
|
||||
|
@ -14,6 +15,10 @@ Window {
|
|||
property color backgroundColor: "#2E2F30"
|
||||
property color backgroundBorderColor: "#555656"
|
||||
|
||||
WindowFramelessHelperMac {
|
||||
target: root;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: backgroundView
|
||||
anchors.fill: parent
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "mousetap/mousetap.h"
|
||||
#include "stream.h"
|
||||
#include "windowframelesshelper.h"
|
||||
#include "windowframelesshelpermac.h"
|
||||
|
||||
static Dialog *g_mainDlg = Q_NULLPTR;
|
||||
|
||||
|
@ -74,6 +75,9 @@ int main(int argc, char *argv[])
|
|||
g_oldMessageHandler = qInstallMessageHandler(myMessageOutput);
|
||||
Stream::init();
|
||||
QApplication app(argc, argv);
|
||||
|
||||
qmlRegisterType<WindowFramelessHelperMac>("barry.uibase", 1, 0, "WindowFramelessHelperMac");
|
||||
|
||||
QQmlApplicationEngine engine("qrc:/MainWindow.qml");
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
|
|
|
@ -3,10 +3,12 @@ FORMS +=
|
|||
HEADERS += \
|
||||
$$PWD/keepratiowidget.h \
|
||||
$$PWD/magneticwidget.h \
|
||||
$$PWD/windowframelesshelper.h
|
||||
$$PWD/windowframelesshelper.h \
|
||||
$$PWD/windowframelesshelpermac.h
|
||||
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/keepratiowidget.cpp \
|
||||
$$PWD/magneticwidget.cpp \
|
||||
$$PWD/windowframelesshelper.cpp
|
||||
$$PWD/windowframelesshelper.cpp \
|
||||
$$PWD/windowframelesshelpermac.mm
|
||||
|
|
24
QtScrcpy/uibase/windowframelesshelpermac.h
Normal file
24
QtScrcpy/uibase/windowframelesshelpermac.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef WINDOWFRAMELESSHELPERMAC_H
|
||||
#define WINDOWFRAMELESSHELPERMAC_H
|
||||
|
||||
#include <QQuickWindow>
|
||||
|
||||
class WindowFramelessHelperMac : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QQuickWindow * target READ target WRITE setTarget NOTIFY targetChanged)
|
||||
|
||||
public:
|
||||
explicit WindowFramelessHelperMac(QObject *parent = nullptr);
|
||||
|
||||
QQuickWindow *target() const;
|
||||
void setTarget(QQuickWindow *target);
|
||||
|
||||
signals:
|
||||
void targetChanged();
|
||||
|
||||
private:
|
||||
QQuickWindow* m_target = nullptr;
|
||||
};
|
||||
|
||||
#endif // WINDOWFRAMELESSHELPERMAC_H
|
49
QtScrcpy/uibase/windowframelesshelpermac.mm
Normal file
49
QtScrcpy/uibase/windowframelesshelpermac.mm
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include "windowframelesshelpermac.h"
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <QOperatingSystemVersion>
|
||||
|
||||
WindowFramelessHelperMac::WindowFramelessHelperMac(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QQuickWindow *WindowFramelessHelperMac::target() const
|
||||
{
|
||||
return m_target;
|
||||
}
|
||||
|
||||
void WindowFramelessHelperMac::setTarget(QQuickWindow *target)
|
||||
{
|
||||
if (target == m_target) {
|
||||
return;
|
||||
}
|
||||
m_target = target;
|
||||
|
||||
//如果当前osx版本老于10.9,则后续代码不可用。转为使用定制的系统按钮,不支持自由缩放窗口及窗口阴影
|
||||
if (QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSView* view = (NSView*)target->winId();
|
||||
if (nullptr == view) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSWindow *window = view.window;
|
||||
if (nullptr == window) {
|
||||
return;
|
||||
}
|
||||
|
||||
//设置标题文字和图标为不可见
|
||||
window.titleVisibility = NSWindowTitleHidden;
|
||||
//设置标题栏为透明
|
||||
window.titlebarAppearsTransparent = YES;
|
||||
//设置不可由标题栏拖动,避免与自定义拖动冲突
|
||||
window.movable = NO;
|
||||
window.hasShadow = YES;
|
||||
//设置view扩展到标题栏
|
||||
window.styleMask |= NSWindowStyleMaskFullSizeContentView;
|
||||
|
||||
emit targetChanged();
|
||||
}
|
Loading…
Add table
Reference in a new issue