SineStriker
2023-12-13 b49663c490141b75605eafa381f6c9e2c736147d
Fix mac
5个文件已修改
95 ■■■■■ 已修改文件
examples/shared/widgetframe/windowbar.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
examples/shared/widgetframe/windowbar_p.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/CMakeLists.txt 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/cocoawindowcontext.mm 74 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/cocoawindowcontext_p.h 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
examples/shared/widgetframe/windowbar.cpp
@@ -1,5 +1,5 @@
#include "WindowBar.h"
#include "WindowBar_p.h"
#include "windowbar.h"
#include "windowbar_p.h"
#include <QtCore/QDebug>
#include <QtGui/QtEvents>
examples/shared/widgetframe/windowbar_p.h
@@ -3,7 +3,7 @@
#include <QBoxLayout>
#include "WindowBar.h"
#include "windowbar.h"
namespace QWK {
src/core/CMakeLists.txt
@@ -21,13 +21,20 @@
)
set(_defines_private)
set(_links_private)
if(WIN32)
    list(APPEND _src
        qwindowkit_windows.h
        qwindowkit_windows.cpp
    )
elseif(NOT APPLE)
elseif(APPLE)
    list(APPEND _links_private
        "-framework Foundation"
        "-framework Cocoa"
        "-framework AppKit"
    )
else()
    list(APPEND _src
        qwindowkit_linux.h
    )
@@ -48,7 +55,7 @@
    elseif(APPLE)
        list(APPEND _src
            contexts/cocoawindowcontext_p.h
            contexts/cocoawindowcontext.cpp
            contexts/cocoawindowcontext.mm
        )
    else()
        list(APPEND _src
@@ -62,6 +69,7 @@
    SOURCES ${_src}
    DEFINES_PRIVATE ${_defines_private}
    LINKS
    LINKS_PRIVATE ${_links_private}
    QT_LINKS Core Gui
    QT_INCLUDE_PRIVATE Core Gui
    INCLUDE_PRIVATE kernel contexts platforms
src/core/contexts/cocoawindowcontext.mm
@@ -1,5 +1,10 @@
#include "cocoawindowcontext_p.h"
#include <objc/runtime.h>
#include <AppKit/AppKit.h>
#include <QtGui/QGuiApplication>
namespace QWK {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@@ -10,13 +15,10 @@
} g_hook{};
#endif
class NSWindowProxy
{
    Q_DISABLE_COPY_MOVE(NSWindowProxy)
    class NSWindowProxy : public QObject {
        Q_OBJECT
public:
    NSWindowProxy(NSWindow *macWindow)
    {
        NSWindowProxy(NSWindow *macWindow) {
        if (instances.contains(macWindow)) {
            return;
        }
@@ -28,8 +30,7 @@
        }
    }
    ~NSWindowProxy() override
    {
        ~NSWindowProxy() override {
        instances.remove(nswindow);
        if (instances.count() <= 0) {
            restoreImplementations();
@@ -39,16 +40,19 @@
    }
public Q_SLOTS:
    void replaceImplementations()
    {
        void replaceImplementations() {
        Method method = class_getInstanceMethod(windowClass, @selector(setStyleMask:));
        Q_ASSERT(method);
        oldSetStyleMask = reinterpret_cast<setStyleMaskPtr>(method_setImplementation(method, reinterpret_cast<IMP>(setStyleMask)));
            oldSetStyleMask = reinterpret_cast<setStyleMaskPtr>(
                method_setImplementation(method, reinterpret_cast<IMP>(setStyleMask)));
        Q_ASSERT(oldSetStyleMask);
        method = class_getInstanceMethod(windowClass, @selector(setTitlebarAppearsTransparent:));
            method =
                class_getInstanceMethod(windowClass, @selector(setTitlebarAppearsTransparent:));
        Q_ASSERT(method);
        oldSetTitlebarAppearsTransparent = reinterpret_cast<setTitlebarAppearsTransparentPtr>(method_setImplementation(method, reinterpret_cast<IMP>(setTitlebarAppearsTransparent)));
            oldSetTitlebarAppearsTransparent =
                reinterpret_cast<setTitlebarAppearsTransparentPtr>(method_setImplementation(
                    method, reinterpret_cast<IMP>(setTitlebarAppearsTransparent)));
        Q_ASSERT(oldSetTitlebarAppearsTransparent);
#if 0
@@ -65,20 +69,22 @@
        method = class_getInstanceMethod(windowClass, @selector(sendEvent:));
        Q_ASSERT(method);
        oldSendEvent = reinterpret_cast<sendEventPtr>(method_setImplementation(method, reinterpret_cast<IMP>(sendEvent)));
            oldSendEvent = reinterpret_cast<sendEventPtr>(
                method_setImplementation(method, reinterpret_cast<IMP>(sendEvent)));
        Q_ASSERT(oldSendEvent);
    }
    void restoreImplementations()
    {
        void restoreImplementations() {
        Method method = class_getInstanceMethod(windowClass, @selector(setStyleMask:));
        Q_ASSERT(method);
        method_setImplementation(method, reinterpret_cast<IMP>(oldSetStyleMask));
        oldSetStyleMask = nil;
        method = class_getInstanceMethod(windowClass, @selector(setTitlebarAppearsTransparent:));
            method =
                class_getInstanceMethod(windowClass, @selector(setTitlebarAppearsTransparent:));
        Q_ASSERT(method);
        method_setImplementation(method, reinterpret_cast<IMP>(oldSetTitlebarAppearsTransparent));
            method_setImplementation(method,
                                     reinterpret_cast<IMP>(oldSetTitlebarAppearsTransparent));
        oldSetTitlebarAppearsTransparent = nil;
#if 0
@@ -99,8 +105,7 @@
        oldSendEvent = nil;
    }
    void setSystemTitleBarVisible(const bool visible)
    {
        void setSystemTitleBarVisible(const bool visible) {
        NSView *nsview = [nswindow contentView];
        if (!nsview) {
            return;
@@ -118,7 +123,8 @@
        nswindow.showsToolbarButton = NO;
        nswindow.movableByWindowBackground = NO;
        nswindow.movable = NO;
        // For some unknown reason, we don't need the following hack in Qt versions below or equal to 6.2.4.
            // For some unknown reason, we don't need the following hack in Qt versions below or
            // equal to 6.2.4.
#if (QT_VERSION > QT_VERSION_CHECK(6, 2, 4))
        [nswindow standardWindowButton:NSWindowCloseButton].hidden = (visible ? NO : YES);
        [nswindow standardWindowButton:NSWindowMiniaturizeButton].hidden = (visible ? NO : YES);
@@ -127,8 +133,7 @@
    }
private:
    static BOOL canBecomeKeyWindow(id obj, SEL sel)
    {
        static BOOL canBecomeKeyWindow(id obj, SEL sel) {
        if (instances.contains(reinterpret_cast<NSWindow *>(obj))) {
            return YES;
        }
@@ -140,8 +145,7 @@
        return YES;
    }
    static BOOL canBecomeMainWindow(id obj, SEL sel)
    {
        static BOOL canBecomeMainWindow(id obj, SEL sel) {
        if (instances.contains(reinterpret_cast<NSWindow *>(obj))) {
            return YES;
        }
@@ -153,8 +157,7 @@
        return YES;
    }
    static void setStyleMask(id obj, SEL sel, NSWindowStyleMask styleMask)
    {
        static void setStyleMask(id obj, SEL sel, NSWindowStyleMask styleMask) {
        if (instances.contains(reinterpret_cast<NSWindow *>(obj))) {
            styleMask |= NSWindowStyleMaskFullSizeContentView;
        }
@@ -164,8 +167,7 @@
        }
    }
    static void setTitlebarAppearsTransparent(id obj, SEL sel, BOOL transparent)
    {
        static void setTitlebarAppearsTransparent(id obj, SEL sel, BOOL transparent) {
        if (instances.contains(reinterpret_cast<NSWindow *>(obj))) {
            transparent = YES;
        }
@@ -175,8 +177,7 @@
        }
    }
    static void sendEvent(id obj, SEL sel, NSEvent *event)
    {
        static void sendEvent(id obj, SEL sel, NSEvent *event) {
        if (oldSendEvent) {
            oldSendEvent(obj, sel, event);
        }
@@ -224,8 +225,7 @@
using ProxyList = QHash<WId, NSWindowProxy *>;
Q_GLOBAL_STATIC(ProxyList, g_proxyList);
    static inline NSWindow *mac_getNSWindow(const WId windowId)
    {
    static inline NSWindow *mac_getNSWindow(const WId windowId) {
        const auto nsview = reinterpret_cast<NSView *>(windowId);
        if (!nsview) {
            return nil;
@@ -233,8 +233,7 @@
        return [nsview window];
    }
static inline void cleanupProxy()
{
    static inline void cleanupProxy() {
    if (g_proxyList()->isEmpty()) {
        return;
    }
@@ -243,8 +242,7 @@
    g_proxyList()->clear();
}
static inline NSWindowProxy *ensureWindowProxy(const WId windowId)
{
    static inline NSWindowProxy *ensureWindowProxy(const WId windowId) {
    auto it = g_proxyList()->find(windowId);
    if (it == g_proxyList()->end()) {
        NSWindow *nswindow = mac_getNSWindow(windowId);
@@ -287,3 +285,5 @@
    }
}
#include "cocoawindowcontext.moc"
src/core/contexts/cocoawindowcontext_p.h
@@ -17,6 +17,9 @@
    protected:
        bool setupHost() override;
    protected:
        WId windowId = 0;
    };
}