Introduced a ScrcpyWindow to enable integration of the scrcpy tool for device screen mirroring within the application. Platform-specific embedding is supported for macOS and Windows, with structure adjustments made in MainWindow and the build system (CMakeLists.txt).
62 lines
1.9 KiB
Plaintext
62 lines
1.9 KiB
Plaintext
#import <Cocoa/Cocoa.h>
|
|
#import <QtCore/QDebug>
|
|
#import <ApplicationServices/ApplicationServices.h>
|
|
#include <QWidget>
|
|
#include <QWindow>
|
|
|
|
void listAllWindows() {
|
|
CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
|
|
|
|
for (NSDictionary *entry in (__bridge NSArray *)windowList) {
|
|
NSString *name = entry[(NSString *)kCGWindowName];
|
|
NSString *owner = entry[(NSString *)kCGWindowOwnerName];
|
|
NSNumber *windowNumber = entry[(NSString *)kCGWindowNumber];
|
|
if (name.length > 0) {
|
|
qDebug() << "Window:" << owner.UTF8String << "-" << name.UTF8String
|
|
<< "ID:" << windowNumber.intValue;
|
|
}
|
|
}
|
|
|
|
CFRelease(windowList);
|
|
}
|
|
|
|
void embedScrcpyMac(QWidget *container) {
|
|
// Получаем список окон
|
|
NSArray *windows = [NSApp windows];
|
|
NSWindow *scrcpyWindow = nil;
|
|
|
|
listAllWindows();
|
|
|
|
for (NSWindow *window in windows) {
|
|
NSString *title = [window title];
|
|
qDebug() << "Found window title:" << title.UTF8String;
|
|
|
|
if ([[window title] isEqualToString:@"scrcpy"]) {
|
|
scrcpyWindow = window;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!scrcpyWindow) {
|
|
qDebug() << "scrcpy window not found";
|
|
return;
|
|
}
|
|
|
|
// Убираем заголовок и рамку
|
|
[scrcpyWindow setStyleMask:NSWindowStyleMaskBorderless];
|
|
|
|
// Получаем координаты окна Qt
|
|
NSView *nativeView = (NSView *)container->winId();
|
|
NSWindow *qtWindow = [nativeView window];
|
|
NSRect frame = [qtWindow frame];
|
|
|
|
// Задаём новый размер и позицию для окна scrcpy
|
|
CGFloat width = frame.size.width;
|
|
CGFloat height = frame.size.height;
|
|
CGFloat x = frame.origin.x;
|
|
CGFloat y = frame.origin.y;
|
|
|
|
[scrcpyWindow setFrame:NSMakeRect(x, y, width, height) display:YES];
|
|
[scrcpyWindow orderFront:nil];
|
|
}
|