mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
feat(window): add exclusive fullscreen support with WM detection
This commit is contained in:
@@ -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
|
||||
@@ -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;
|
||||
|
||||
45
include/Cubed/tools/system_window_manager.hpp
Normal file
45
include/Cubed/tools/system_window_manager.hpp
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user