mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
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:
@@ -5,40 +5,23 @@
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
namespace Cubed {
|
||||
enum class WindowManager { WINDOWS, UNKNOWN, NIRI, SWAY, HYPRLAND, KDE, GNOME };
|
||||
|
||||
namespace Tools {
|
||||
inline WindowManager detect_wm() {
|
||||
inline std::string detect_wm() {
|
||||
#ifdef _WIN32
|
||||
return WindowManager::WINDOWS;
|
||||
return "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;
|
||||
|
||||
if (!desktop) {
|
||||
return "Unknown";
|
||||
}
|
||||
Logger::info("XDG_CURRENT_DESKTOP: {}", desktop);
|
||||
return std::string(desktop);
|
||||
#endif
|
||||
|
||||
return WindowManager::UNKNOWN;
|
||||
return "Unknown";
|
||||
}
|
||||
} // namespace Tools
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Cubed/debug_collector.hpp"
|
||||
|
||||
#include "Cubed/tools/system_info.hpp"
|
||||
#include "Cubed/tools/system_window_manager.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
#include <SDL3/SDL_video.h>
|
||||
@@ -72,7 +73,12 @@ void DebugCollector::init(int width, int height) {
|
||||
} else {
|
||||
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
|
||||
auto& cpu_text = m_widget.add_child<Label>();
|
||||
cpu_text.set_text("CPU: " + Tools::get_cpu_info()).set_scale(SCALE);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "Cubed/tools/env_tools.hpp"
|
||||
#include "Cubed/tools/font.hpp"
|
||||
#include "Cubed/tools/log.hpp"
|
||||
#include "Cubed/tools/system_window_manager.hpp"
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
@@ -188,20 +187,12 @@ void Window::init(const Argument& argument) {
|
||||
}
|
||||
|
||||
bool default_exclusive = false;
|
||||
auto wm = Tools::detect_wm();
|
||||
switch (wm) {
|
||||
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:
|
||||
|
||||
#ifdef _WIN32
|
||||
default_exclusive = false;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
default_exclusive = true;
|
||||
#endif
|
||||
|
||||
m_enable_exclusive =
|
||||
m_config.get("enable_exclusive_fullscreen", default_exclusive);
|
||||
|
||||
Reference in New Issue
Block a user