refactor: simplify WM detection and exclusive fullscreen default

Removed WindowManager enum; detect_wm() now returns string directly.
Default exclusive fullscreen based on platform (true on Linux).
Added WM info to debug overlay.
This commit is contained in:
2026-07-17 17:54:28 +08:00
parent 1f334567c8
commit 106cc84e62
3 changed files with 21 additions and 41 deletions

View File

@@ -5,40 +5,23 @@
#include <cstdlib> #include <cstdlib>
#include <string> #include <string>
namespace Cubed { namespace Cubed {
enum class WindowManager { WINDOWS, UNKNOWN, NIRI, SWAY, HYPRLAND, KDE, GNOME };
namespace Tools { namespace Tools {
inline WindowManager detect_wm() { inline std::string detect_wm() {
#ifdef _WIN32 #ifdef _WIN32
return WindowManager::WINDOWS; return "Windows";
#endif #endif
#ifdef __linux__ #ifdef __linux__
const char* desktop = getenv("XDG_CURRENT_DESKTOP"); const char* desktop = getenv("XDG_CURRENT_DESKTOP");
if (!desktop) {
if (!desktop) return "Unknown";
return WindowManager::UNKNOWN; }
Logger::info("XDG_CURRENT_DESKTOP {}", desktop); Logger::info("XDG_CURRENT_DESKTOP: {}", desktop);
std::string wm(desktop); return std::string(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 #endif
return WindowManager::UNKNOWN; return "Unknown";
} }
} // namespace Tools } // namespace Tools

View File

@@ -1,6 +1,7 @@
#include "Cubed/debug_collector.hpp" #include "Cubed/debug_collector.hpp"
#include "Cubed/tools/system_info.hpp" #include "Cubed/tools/system_info.hpp"
#include "Cubed/tools/system_window_manager.hpp"
#include "version.hpp" #include "version.hpp"
#include <SDL3/SDL_video.h> #include <SDL3/SDL_video.h>
@@ -72,7 +73,12 @@ void DebugCollector::init(int width, int height) {
} else { } else {
os_text.set_text("OS: Unknown"); os_text.set_text("OS: Unknown");
} }
{
std::string wm{"WM: "};
wm.append(Tools::detect_wm());
auto& wm_label = m_widget.add_child<Label>();
wm_label.set_text(wm).set_scale(SCALE);
}
// cpu // cpu
auto& cpu_text = m_widget.add_child<Label>(); auto& cpu_text = m_widget.add_child<Label>();
cpu_text.set_text("CPU: " + Tools::get_cpu_info()).set_scale(SCALE); cpu_text.set_text("CPU: " + Tools::get_cpu_info()).set_scale(SCALE);

View File

@@ -6,7 +6,6 @@
#include "Cubed/tools/env_tools.hpp" #include "Cubed/tools/env_tools.hpp"
#include "Cubed/tools/font.hpp" #include "Cubed/tools/font.hpp"
#include "Cubed/tools/log.hpp" #include "Cubed/tools/log.hpp"
#include "Cubed/tools/system_window_manager.hpp"
#include <imgui.h> #include <imgui.h>
#include <imgui_impl_opengl3.h> #include <imgui_impl_opengl3.h>
@@ -188,20 +187,12 @@ void Window::init(const Argument& argument) {
} }
bool default_exclusive = false; bool default_exclusive = false;
auto wm = Tools::detect_wm();
switch (wm) { #ifdef _WIN32
case WindowManager::NIRI:
case WindowManager::SWAY:
case WindowManager::HYPRLAND:
default_exclusive = true;
break;
case WindowManager::WINDOWS:
case WindowManager::GNOME:
case WindowManager::KDE:
case WindowManager::UNKNOWN:
default_exclusive = false; default_exclusive = false;
break; #else
} default_exclusive = true;
#endif
m_enable_exclusive = m_enable_exclusive =
m_config.get("enable_exclusive_fullscreen", default_exclusive); m_config.get("enable_exclusive_fullscreen", default_exclusive);