2025-07-22 17:12:24 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2025-07-22 16:31:36 -04:00
|
|
|
#include "qt_common.h"
|
2023-05-01 20:27:45 -04:00
|
|
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QStringLiteral>
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "core/frontend/emu_window.h"
|
|
|
|
|
2025-07-22 23:23:14 -04:00
|
|
|
#include <QFile>
|
2025-07-23 21:10:17 -04:00
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2025-07-22 23:23:14 -04:00
|
|
|
#include <JlCompress.h>
|
|
|
|
|
2025-07-23 01:21:18 -04:00
|
|
|
#if !defined(WIN32) && !defined(__APPLE__)
|
|
|
|
#include <qpa/qplatformnativeinterface.h>
|
2023-06-30 23:35:07 -07:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#include <objc/message.h>
|
2023-05-01 20:27:45 -04:00
|
|
|
#endif
|
|
|
|
|
2023-05-03 18:11:34 -04:00
|
|
|
namespace QtCommon {
|
2025-08-30 19:48:13 -04:00
|
|
|
|
|
|
|
QObject *rootObject = nullptr;
|
|
|
|
Core::System *system = nullptr;
|
2025-07-22 16:31:36 -04:00
|
|
|
|
2025-07-22 17:05:57 -04:00
|
|
|
Core::Frontend::WindowSystemType GetWindowSystemType()
|
|
|
|
{
|
2023-05-01 20:27:45 -04:00
|
|
|
// Determine WSI type based on Qt platform.
|
|
|
|
QString platform_name = QGuiApplication::platformName();
|
|
|
|
if (platform_name == QStringLiteral("windows"))
|
|
|
|
return Core::Frontend::WindowSystemType::Windows;
|
|
|
|
else if (platform_name == QStringLiteral("xcb"))
|
|
|
|
return Core::Frontend::WindowSystemType::X11;
|
|
|
|
else if (platform_name == QStringLiteral("wayland"))
|
|
|
|
return Core::Frontend::WindowSystemType::Wayland;
|
|
|
|
else if (platform_name == QStringLiteral("wayland-egl"))
|
|
|
|
return Core::Frontend::WindowSystemType::Wayland;
|
|
|
|
else if (platform_name == QStringLiteral("cocoa"))
|
|
|
|
return Core::Frontend::WindowSystemType::Cocoa;
|
|
|
|
else if (platform_name == QStringLiteral("android"))
|
|
|
|
return Core::Frontend::WindowSystemType::Android;
|
|
|
|
|
|
|
|
LOG_CRITICAL(Frontend, "Unknown Qt platform {}!", platform_name.toStdString());
|
|
|
|
return Core::Frontend::WindowSystemType::Windows;
|
|
|
|
} // namespace Core::Frontend::WindowSystemType
|
|
|
|
|
2025-07-22 17:05:57 -04:00
|
|
|
Core::Frontend::EmuWindow::WindowSystemInfo GetWindowSystemInfo(QWindow* window)
|
|
|
|
{
|
2023-05-01 20:27:45 -04:00
|
|
|
Core::Frontend::EmuWindow::WindowSystemInfo wsi;
|
|
|
|
wsi.type = GetWindowSystemType();
|
|
|
|
|
2023-06-30 23:35:07 -07:00
|
|
|
#if defined(WIN32)
|
2023-05-01 20:27:45 -04:00
|
|
|
// Our Win32 Qt external doesn't have the private API.
|
2023-06-30 23:35:07 -07:00
|
|
|
wsi.render_surface = reinterpret_cast<void*>(window->winId());
|
|
|
|
#elif defined(__APPLE__)
|
2025-07-22 17:05:57 -04:00
|
|
|
wsi.render_surface = reinterpret_cast<void* (*) (id, SEL)>(
|
|
|
|
objc_msgSend)(reinterpret_cast<id>(window->winId()), sel_registerName("layer"));
|
2023-05-01 20:27:45 -04:00
|
|
|
#else
|
|
|
|
QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface();
|
|
|
|
wsi.display_connection = pni->nativeResourceForWindow("display", window);
|
|
|
|
if (wsi.type == Core::Frontend::WindowSystemType::Wayland)
|
|
|
|
wsi.render_surface = window ? pni->nativeResourceForWindow("surface", window) : nullptr;
|
|
|
|
else
|
|
|
|
wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
|
|
|
|
#endif
|
|
|
|
wsi.render_surface_scale = window ? static_cast<float>(window->devicePixelRatio()) : 1.0f;
|
|
|
|
|
|
|
|
return wsi;
|
|
|
|
}
|
2025-07-22 16:31:36 -04:00
|
|
|
|
2025-08-30 19:48:13 -04:00
|
|
|
const QString tr(const char* str)
|
2025-07-22 17:05:57 -04:00
|
|
|
{
|
2025-08-30 19:48:13 -04:00
|
|
|
return QGuiApplication::tr(str);
|
2025-07-22 17:05:57 -04:00
|
|
|
}
|
|
|
|
|
2025-08-30 19:48:13 -04:00
|
|
|
const QString tr(const std::string& str)
|
2025-07-22 23:23:14 -04:00
|
|
|
{
|
2025-08-30 19:48:13 -04:00
|
|
|
return QGuiApplication::tr(str.c_str());
|
2025-07-22 16:31:36 -04:00
|
|
|
}
|
2025-08-30 19:48:13 -04:00
|
|
|
|
2025-07-22 23:23:14 -04:00
|
|
|
} // namespace QtCommon
|