diff --git a/QtScrcpy/uibase/windowframelesshelper.cpp b/QtScrcpy/uibase/windowframelesshelper.cpp index 2645661..d00d75e 100644 --- a/QtScrcpy/uibase/windowframelesshelper.cpp +++ b/QtScrcpy/uibase/windowframelesshelper.cpp @@ -24,3 +24,7 @@ void WindowFramelessHelper::setTarget(QQuickWindow *target) emit targetChanged(); } + +void WindowFramelessHelper::updateStyle() { + +} diff --git a/QtScrcpy/uibase/windowframelesshelper.h b/QtScrcpy/uibase/windowframelesshelper.h index 0ce961e..b16459f 100644 --- a/QtScrcpy/uibase/windowframelesshelper.h +++ b/QtScrcpy/uibase/windowframelesshelper.h @@ -14,6 +14,9 @@ public: QQuickWindow *target() const; void setTarget(QQuickWindow *target); +protected: + void updateStyle(); + signals: void targetChanged(); diff --git a/QtScrcpy/uibase/windowframelesshelper.mm b/QtScrcpy/uibase/windowframelesshelper.mm index a768def..cf166de 100644 --- a/QtScrcpy/uibase/windowframelesshelper.mm +++ b/QtScrcpy/uibase/windowframelesshelper.mm @@ -2,6 +2,70 @@ #include #include +#import +#include + +void SwizzleSelector(Class originalCls, SEL originalSelector, Class swizzledCls, SEL swizzledSelector) { + Method originalMethod = class_getInstanceMethod(originalCls, originalSelector); + Method swizzledMethod = class_getInstanceMethod(swizzledCls, swizzledSelector); + + BOOL didAddMethod = + class_addMethod(originalCls, + originalSelector, + method_getImplementation(swizzledMethod), + method_getTypeEncoding(swizzledMethod)); + + if (didAddMethod) { + class_replaceMethod(originalCls, + swizzledSelector, + method_getImplementation(originalMethod), + method_getTypeEncoding(originalMethod)); + } else { + method_exchangeImplementations(originalMethod, swizzledMethod); + } +} + + +@interface NSWindow(FilterWindow) +@end +@implementation NSWindow(FilterWindow) ++ (void)load +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + SwizzleSelector([self class], + @selector(setStyleMask:), + [self class], + @selector(filter_setStyleMask:)); + SwizzleSelector([self class], + @selector(setTitlebarAppearsTransparent:), + [self class], + @selector(filter_setTitlebarAppearsTransparent:)); + }); +} + +- (void)filter_setStyleMask:(NSWindowStyleMask)styleMask +{ + [self filter_setStyleMask:styleMask]; + + //设置标题文字和图标为不可见 + self.titleVisibility = NSWindowTitleHidden; + //设置标题栏为透明 + self.titlebarAppearsTransparent = YES; + //设置不可由标题栏拖动,避免与自定义拖动冲突 + self.movable = NO; + self.hasShadow = YES; + //设置view扩展到标题栏 + if (!(self.styleMask & NSWindowStyleMaskFullSizeContentView)) { + self.styleMask |= NSWindowStyleMaskFullSizeContentView; + } +} + +- (void)filter_setTitlebarAppearsTransparent:(BOOL)titlebarAppearsTransparent +{ + [self filter_setTitlebarAppearsTransparent:titlebarAppearsTransparent]; +} +@end WindowFramelessHelper::WindowFramelessHelper(QObject *parent) : QObject(parent) { @@ -20,12 +84,22 @@ void WindowFramelessHelper::setTarget(QQuickWindow *target) } m_target = target; + //updateStyle(); + + emit targetChanged(); +} +/* +void WindowFramelessHelper::updateStyle() { + if (!m_target) { + return; + } + //如果当前osx版本老于10.9,则后续代码不可用。转为使用定制的系统按钮,不支持自由缩放窗口及窗口阴影 if (QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite) { return; } - NSView* view = (NSView*)target->winId(); + NSView* view = (NSView*)m_target->winId(); if (nullptr == view) { return; } @@ -44,6 +118,6 @@ void WindowFramelessHelper::setTarget(QQuickWindow *target) window.hasShadow = YES; //设置view扩展到标题栏 window.styleMask |= NSWindowStyleMaskFullSizeContentView; - - emit targetChanged(); } + +*/