feat: Add build type system and improve fullscreen exit handling

- Add CITRON_BUILD_TYPE CMake variable (Stable/Nightly)
- Refactor GenerateSCMRev to use build type instead of repo parsing
- Update window title to display build type (Nightly/Stable)
- Improve fullscreen exit hotkey using dedicated QAction

Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-12-03 12:00:07 +10:00
parent 45d58d53aa
commit 54cba480e6
3 changed files with 89 additions and 50 deletions

View File

@@ -6,6 +6,15 @@ cmake_minimum_required(VERSION 3.22)
project(citron) project(citron)
# Define the build type, defaulting to "Nightly" for development and CI builds.
set(CITRON_BUILD_TYPE "Stable" CACHE STRING "The build type for the emulator (e.g., Stable, Nightly)")
# For cmake-gui, this creates a dropdown to select the build type.
set_property(CACHE CITRON_BUILD_TYPE PROPERTY STRINGS Stable Nightly)
# Pass the build type to the C++ source code as a preprocessor definition.
add_definitions("-DCITRON_BUILD_TYPE=\"${CITRON_BUILD_TYPE}\"")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules")
@@ -558,7 +567,7 @@ endif()
function(set_citron_qt_components) function(set_citron_qt_components)
# Best practice is to ask for all components at once, so they are from the same version # Best practice is to ask for all components at once, so they are from the same version
set(CITRON_QT_COMPONENTS2 Core Widgets Concurrent) set(CITRON_QT_COMPONENTS2 Core Widgets Concurrent GuiPrivate)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
list(APPEND CITRON_QT_COMPONENTS2 DBus) list(APPEND CITRON_QT_COMPONENTS2 DBus)
endif() endif()

View File

@@ -20,12 +20,26 @@ if (NOT GIT_BRANCH)
endif() endif()
get_timestamp(BUILD_DATE) get_timestamp(BUILD_DATE)
# Generate cpp with Git revision from template #
# Also if this is a CI build, add the build name (ie: Nightly, Canary) to the scm_rev file as well # Generate build information based on the CITRON_BUILD_TYPE variable.
set(REPO_NAME "") #
set(BUILD_VERSION "0") if(CITRON_BUILD_TYPE STREQUAL "Stable")
set(BUILD_ID ${DISPLAY_VERSION}) # For Stable builds, use a clean version string and an empty build name for the title bar.
if (BUILD_REPOSITORY) set(BUILD_FULLNAME "")
# These variables are set in the root CMakeLists.txt, but we provide a fallback.
if(DEFINED CITRON_VERSION_MAJOR)
set(BUILD_VERSION "${CITRON_VERSION_MAJOR}.${CITRON_VERSION_MINOR}.${CITRON_VERSION_PATCH}")
else()
set(BUILD_VERSION "0.11.0") # Fallback stable version
endif()
set(BUILD_ID ${DISPLAY_VERSION})
else()
# For Nightly or local developer builds, use the existing logic to generate a name and use the git hash.
set(REPO_NAME "")
set(BUILD_VERSION "0")
set(BUILD_ID ${DISPLAY_VERSION})
if (BUILD_REPOSITORY)
# regex capture the string nightly or canary into CMAKE_MATCH_1 # regex capture the string nightly or canary into CMAKE_MATCH_1
string(REGEX MATCH "citron-emu/citron-?(.*)" OUTVAR ${BUILD_REPOSITORY}) string(REGEX MATCH "citron-emu/citron-?(.*)" OUTVAR ${BUILD_REPOSITORY})
if ("${CMAKE_MATCH_COUNT}" GREATER 0) if ("${CMAKE_MATCH_COUNT}" GREATER 0)
@@ -51,13 +65,15 @@ if (BUILD_REPOSITORY)
endif() endif()
endif() endif()
endif() endif()
endif() endif()
# Add a fallback for local builds # Add a fallback for local builds
# If BUILD_VERSION is still "0", it means the CI-specific logic was not executed. # If BUILD_VERSION is still "0", it means the CI-specific logic was not executed.
# In that case, we should use the git description which contains the commit hash. # In that case, we should use the git description which contains the commit hash.
if (BUILD_VERSION STREQUAL "0") if (BUILD_VERSION STREQUAL "0")
set(BUILD_FULLNAME "Nightly ") # Ensure local builds are also identified as Nightly
set(BUILD_VERSION ${GIT_DESC}) set(BUILD_VERSION ${GIT_DESC})
endif()
endif() endif()
configure_file(scm_rev.cpp.in scm_rev.cpp @ONLY) configure_file(scm_rev.cpp.in scm_rev.cpp @ONLY)

View File

@@ -1454,6 +1454,20 @@ void GMainWindow::InitializeHotkeys() {
LinkActionShortcut(ui->action_Show_Room, QStringLiteral("Multiplayer Show Current Room")); LinkActionShortcut(ui->action_Show_Room, QStringLiteral("Multiplayer Show Current Room"));
LinkActionShortcut(ui->action_Leave_Room, QStringLiteral("Multiplayer Leave Room")); LinkActionShortcut(ui->action_Leave_Room, QStringLiteral("Multiplayer Leave Room"));
// Create and connect a dedicated, robust QAction for exiting fullscreen.
action_exit_fullscreen = new QAction(this);
connect(action_exit_fullscreen, &QAction::triggered, this, [this] {
if (emulation_running && ui->action_Fullscreen->isChecked()) {
// Un-check the toggle to keep the UI in sync and then exit fullscreen.
ui->action_Fullscreen->setChecked(false);
ToggleFullscreen();
}
});
// Now bind the "Exit Fullscreen" hotkey (Esc by default) to this new QAction.
LinkActionShortcut(action_exit_fullscreen, QStringLiteral("Exit Fullscreen"));
render_window->addAction(action_exit_fullscreen);
static const QString main_window = QStringLiteral("Main Window"); static const QString main_window = QStringLiteral("Main Window");
const auto connect_shortcut = [&]<typename Fn>(const QString& action_name, const Fn& function) { const auto connect_shortcut = [&]<typename Fn>(const QString& action_name, const Fn& function) {
const auto* hotkey = const auto* hotkey =
@@ -1466,12 +1480,6 @@ void GMainWindow::InitializeHotkeys() {
Qt::QueuedConnection); Qt::QueuedConnection);
}; };
connect_shortcut(QStringLiteral("Exit Fullscreen"), [&] {
if (emulation_running && ui->action_Fullscreen->isChecked()) {
ui->action_Fullscreen->setChecked(false);
ToggleFullscreen();
}
});
connect_shortcut(QStringLiteral("Change Adapting Filter"), connect_shortcut(QStringLiteral("Change Adapting Filter"),
&GMainWindow::OnToggleAdaptingFilter); &GMainWindow::OnToggleAdaptingFilter);
connect_shortcut(QStringLiteral("Change Docked Mode"), &GMainWindow::OnToggleDockedMode); connect_shortcut(QStringLiteral("Change Docked Mode"), &GMainWindow::OnToggleDockedMode);
@@ -5334,19 +5342,25 @@ void GMainWindow::MigrateConfigFiles() {
void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_view title_version, void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_view title_version,
std::string_view gpu_vendor) { std::string_view gpu_vendor) {
std::string window_title = "citron | 0.11.0"; // Build the base title from the CMake-generated variables.
#ifdef CITRON_ENABLE_PGO_USE std::string base_title = "citron ";
window_title += " | PGO"; base_title += Common::g_build_fullname; // This is "Nightly " or "" for Stable
#endif base_title += "| ";
base_title += Common::g_build_version; // This is the git hash or Stable version tag.
// Add the PGO tag if enabled.
#ifdef CITRON_ENABLE_PGO_USE
base_title += " | PGO";
#endif
if (title_name.empty()) { if (title_name.empty()) {
setWindowTitle(QString::fromStdString(window_title)); setWindowTitle(QString::fromStdString(base_title));
} else { } else {
const auto run_title = [window_title, title_name, title_version, gpu_vendor]() { const auto run_title = [&]() {
if (title_version.empty()) { if (title_version.empty()) {
return fmt::format("{} | {} | {}", window_title, title_name, gpu_vendor); return fmt::format("{} | {} | {}", base_title, title_name, gpu_vendor);
} }
return fmt::format("{} | {} | {} | {}", window_title, title_name, title_version, return fmt::format("{} | {} | {} | {}", base_title, title_name, title_version,
gpu_vendor); gpu_vendor);
}(); }();
setWindowTitle(QString::fromStdString(run_title)); setWindowTitle(QString::fromStdString(run_title));