feat(window): add exclusive fullscreen support with WM detection

This commit is contained in:
2026-07-17 17:42:52 +08:00
parent c5d90fe82e
commit 1f334567c8
6 changed files with 145 additions and 46 deletions

View File

@@ -9,5 +9,6 @@ struct Argument {
std::optional<bool> no_debug;
std::optional<std::string> language;
std::optional<std::string> video_driver;
std::optional<bool> enable_exclusive;
};
} // namespace Cubed

View File

@@ -184,14 +184,14 @@ inline std::string get_compiler_info() {
#else
result = "Unknown Compiler";
#endif
constexpr long cpp_version =
constexpr long CPP_VERSION =
#ifdef _MSC_VER
_MSVC_LANG;
#else
__cplusplus;
#endif
result += " (C++";
result += std::to_string(cpp_version);
result += std::to_string(CPP_VERSION);
result += ")";
return result;

View File

@@ -0,0 +1,45 @@
#pragma once
#include "Cubed/tools/log.hpp"
#include <cstdlib>
#include <string>
namespace Cubed {
enum class WindowManager { WINDOWS, UNKNOWN, NIRI, SWAY, HYPRLAND, KDE, GNOME };
namespace Tools {
inline WindowManager detect_wm() {
#ifdef _WIN32
return WindowManager::WINDOWS;
#endif
#ifdef __linux__
const char* desktop = getenv("XDG_CURRENT_DESKTOP");
if (!desktop)
return WindowManager::UNKNOWN;
Logger::info("XDG_CURRENT_DESKTOP {}", desktop);
std::string wm(desktop);
if (wm.find("niri") != std::string::npos)
return WindowManager::NIRI;
if (wm.find("sway") != std::string::npos)
return WindowManager::SWAY;
if (wm.find("Hyprland") != std::string::npos)
return WindowManager::HYPRLAND;
if (wm.find("KDE") != std::string::npos)
return WindowManager::KDE;
if (wm.find("GNOME") != std::string::npos)
return WindowManager::GNOME;
#endif
return WindowManager::UNKNOWN;
}
} // namespace Tools
} // namespace Cubed

View File

@@ -49,6 +49,7 @@ private:
bool m_mouse_enable = true;
bool m_imgui_init = false;
bool m_game_running = false;
bool m_enable_exclusive = false;
SDL_Window* m_window;
SDL_GLContext m_context;
int m_window_width = 0;
@@ -61,6 +62,9 @@ private:
bool handle_key_event(const KeyEvent& e);
bool handle_window_resize_event(const WindowResizeEvent& e);
bool handle_mouse_button_event(const MouseButtonEvent& e);
void set_exclusive_fullscreen(bool full);
void set_borderless_fullscreen(bool full);
};
} // namespace Cubed