1
0
mirror of synced 2024-11-24 15:50:16 +01:00

feat: Allow switching off borderless window mode

This commit is contained in:
WerWolv 2024-02-11 14:12:14 +01:00
parent daf4e5cad6
commit 5cfcca0bc4
11 changed files with 47 additions and 39 deletions

View File

@ -12,7 +12,7 @@
bool isMacosFullScreenModeEnabled(GLFWwindow *window); bool isMacosFullScreenModeEnabled(GLFWwindow *window);
float getBackingScaleFactor(); float getBackingScaleFactor();
void setupMacosWindowStyle(GLFWwindow *window); void setupMacosWindowStyle(GLFWwindow *window, bool borderlessWindowMode);
} }

View File

@ -44,16 +44,19 @@
return [[NSScreen mainScreen] backingScaleFactor]; return [[NSScreen mainScreen] backingScaleFactor];
} }
void setupMacosWindowStyle(GLFWwindow *window) { void setupMacosWindowStyle(GLFWwindow *window, bool borderlessWindowMode) {
NSWindow* cocoaWindow = glfwGetCocoaWindow(window); NSWindow* cocoaWindow = glfwGetCocoaWindow(window);
cocoaWindow.titleVisibility = NSWindowTitleHidden; cocoaWindow.titleVisibility = NSWindowTitleHidden;
cocoaWindow.titlebarAppearsTransparent = YES;
cocoaWindow.styleMask |= NSWindowStyleMaskFullSizeContentView;
[cocoaWindow setOpaque:NO]; if (borderlessWindowMode) {
[cocoaWindow setHasShadow:YES]; cocoaWindow.titlebarAppearsTransparent = YES;
[cocoaWindow setBackgroundColor:[NSColor colorWithWhite: 0 alpha: 0.001f]]; cocoaWindow.styleMask |= NSWindowStyleMaskFullSizeContentView;
[cocoaWindow setOpaque:NO];
[cocoaWindow setHasShadow:YES];
[cocoaWindow setBackgroundColor:[NSColor colorWithWhite: 0 alpha: 0.001f]];
}
} }
bool isMacosFullScreenModeEnabled(GLFWwindow *window) { bool isMacosFullScreenModeEnabled(GLFWwindow *window) {

View File

@ -41,8 +41,6 @@ namespace hex {
} }
void Window::setupNativeWindow() { void Window::setupNativeWindow() {
ImHexApi::System::impl::setBorderlessWindowMode(true);
bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection(); bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection();
EventOSThemeChanged::subscribe(this, [themeFollowSystem] { EventOSThemeChanged::subscribe(this, [themeFollowSystem] {
if (!themeFollowSystem) return; if (!themeFollowSystem) return;
@ -63,7 +61,7 @@ namespace hex {
} }
}); });
setupMacosWindowStyle(m_window); setupMacosWindowStyle(m_window, ImHexApi::System::isBorderlessWindowModeEnabled());
} }
void Window::beginNativeWindowFrame() { void Window::beginNativeWindowFrame() {

View File

@ -296,8 +296,6 @@ namespace hex {
log::impl::redirectToFile(); log::impl::redirectToFile();
} }
ImHexApi::System::impl::setBorderlessWindowMode(true);
// Add plugin library folders to dll search path // Add plugin library folders to dll search path
for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Libraries)) { for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Libraries)) {
if (std::fs::exists(path)) if (std::fs::exists(path))

View File

@ -482,6 +482,7 @@
"hex.builtin.setting.imhex": "ImHex", "hex.builtin.setting.imhex": "ImHex",
"hex.builtin.setting.imhex.recent_files": "Zuletzt geöffnete Dateien", "hex.builtin.setting.imhex.recent_files": "Zuletzt geöffnete Dateien",
"hex.builtin.setting.interface": "Aussehen", "hex.builtin.setting.interface": "Aussehen",
"hex.builtin.setting.interface.native_window_decorations": "Benutze OS Fensterdekorationen",
"hex.builtin.setting.interface.color": "Farbdesign", "hex.builtin.setting.interface.color": "Farbdesign",
"hex.builtin.setting.interface.crisp_scaling": "Gestochen scharfe Skallierung aktivieren", "hex.builtin.setting.interface.crisp_scaling": "Gestochen scharfe Skallierung aktivieren",
"hex.builtin.setting.interface.fps": "FPS Limit", "hex.builtin.setting.interface.fps": "FPS Limit",

View File

@ -469,6 +469,7 @@
"hex.builtin.setting.imhex.recent_files": "Recent Files", "hex.builtin.setting.imhex.recent_files": "Recent Files",
"hex.builtin.setting.interface": "Interface", "hex.builtin.setting.interface": "Interface",
"hex.builtin.setting.interface.always_show_provider_tabs": "Always show Provider Tabs", "hex.builtin.setting.interface.always_show_provider_tabs": "Always show Provider Tabs",
"hex.builtin.setting.interface.native_window_decorations": "Use OS Window decorations",
"hex.builtin.setting.interface.color": "Color theme", "hex.builtin.setting.interface.color": "Color theme",
"hex.builtin.setting.interface.crisp_scaling": "Enable crisp scaling", "hex.builtin.setting.interface.crisp_scaling": "Enable crisp scaling",
"hex.builtin.setting.interface.fps": "FPS Limit", "hex.builtin.setting.interface.fps": "FPS Limit",

View File

@ -601,6 +601,28 @@ namespace hex::plugin::builtin {
i32 m_currIndex = 0; i32 m_currIndex = 0;
}; };
bool getDefaultBorderlessWindowMode() {
bool result = false;
#if defined (OS_WINDOWS) || defined(OS_MACOS)
result = true;
#endif
// Intel's OpenGL driver has weird bugs that cause the drawn window to be offset to the bottom right.
// This can be fixed by either using Mesa3D's OpenGL Software renderer or by simply disabling it.
// If you want to try if it works anyways on your GPU, set the hex.builtin.setting.interface.force_borderless_window_mode setting to 1
if (ImHexApi::System::isBorderlessWindowModeEnabled()) {
const bool isIntelGPU = hex::containsIgnoreCase(ImHexApi::System::getGPUVendor(), "Intel");
result = !isIntelGPU;
if (isIntelGPU)
log::warn("Intel GPU detected! Intel's OpenGL driver has bugs that can cause issues when using ImHex. If you experience any rendering bugs, please try the Mesa3D Software Renderer");
}
return result;
}
} }
void registerSettings() { void registerSettings() {
@ -686,17 +708,23 @@ namespace hex::plugin::builtin {
#endif #endif
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.multi_windows", MultiWindowSupportEnabledDefault).requiresRestart(); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.multi_windows", MultiWindowSupportEnabledDefault).requiresRestart();
#if !defined(OS_WEB)
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.native_window_decorations", !getDefaultBorderlessWindowMode()).requiresRestart();
#endif
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.restore_window_pos", false); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.restore_window_pos", false);
ContentRegistry::Settings::add<Widgets::ColorPicker>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.highlight_color", ImColor(0x80, 0x80, 0xC0, 0x60)); ContentRegistry::Settings::add<Widgets::ColorPicker>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.highlight_color", ImColor(0x80, 0x80, 0xC0, 0x60));
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.sync_scrolling", false); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.sync_scrolling", false);
ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.byte_padding", 0, 0, 50); ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.byte_padding", 0, 0, 50);
ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.char_padding", 0, 0, 50); ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.char_padding", 0, 0, 50);
} }
/* Fonts */ /* Fonts */
{ {
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.glyphs", "hex.builtin.setting.font.load_all_unicode_chars", false) ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.glyphs", "hex.builtin.setting.font.load_all_unicode_chars", false)
.requiresRestart(); .requiresRestart();
@ -823,6 +851,9 @@ namespace hex::plugin::builtin {
ImHexApi::System::enableSystemThemeDetection(false); ImHexApi::System::enableSystemThemeDetection(false);
ThemeManager::changeTheme(theme); ThemeManager::changeTheme(theme);
} }
auto borderlessWindowMode = !ContentRegistry::Settings::read<bool>("hex.builtin.setting.interface", "hex.builtin.setting.interface.native_window_decorations", !getDefaultBorderlessWindowMode());
ImHexApi::System::impl::setBorderlessWindowMode(borderlessWindowMode);
} }
static void loadFolderSettings() { static void loadFolderSettings() {

View File

@ -425,17 +425,4 @@ namespace hex::plugin::builtin {
ContentRegistry::Interface::addMenuItemToToolbar("hex.builtin.menu.edit.bookmark.create", ImGuiCustomCol_ToolbarGreen); ContentRegistry::Interface::addMenuItemToToolbar("hex.builtin.menu.edit.bookmark.create", ImGuiCustomCol_ToolbarGreen);
} }
void handleBorderlessWindowMode() {
// Intel's OpenGL driver has weird bugs that cause the drawn window to be offset to the bottom right.
// This can be fixed by either using Mesa3D's OpenGL Software renderer or by simply disabling it.
// If you want to try if it works anyways on your GPU, set the hex.builtin.setting.interface.force_borderless_window_mode setting to 1
if (ImHexApi::System::isBorderlessWindowModeEnabled()) {
bool isIntelGPU = hex::containsIgnoreCase(ImHexApi::System::getGPUVendor(), "Intel");
ImHexApi::System::impl::setBorderlessWindowMode(!isIntelGPU);
if (isIntelGPU)
log::warn("Intel GPU detected! Intel's OpenGL driver has bugs that can cause issues when using ImHex. If you experience any rendering bugs, please try the Mesa3D Software Renderer");
}
}
} }

View File

@ -7,6 +7,8 @@
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
void loadWorkspaces() { void loadWorkspaces() {
WorkspaceManager::reset();
for (const auto &defaultPath : fs::getDefaultPaths(fs::ImHexPath::Workspaces)) { for (const auto &defaultPath : fs::getDefaultPaths(fs::ImHexPath::Workspaces)) {
for (const auto &entry : std::fs::directory_iterator(defaultPath)) { for (const auto &entry : std::fs::directory_iterator(defaultPath)) {
if (!entry.is_regular_file()) if (!entry.is_regular_file())

View File

@ -121,6 +121,5 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
addToolbarItems(); addToolbarItems();
addGlobalUIItems(); addGlobalUIItems();
handleBorderlessWindowMode();
setupOutOfBoxExperience(); setupOutOfBoxExperience();
} }

View File

@ -35,11 +35,7 @@ static void detectSystemTheme() {
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size); auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
if (error == ERROR_SUCCESS) { if (error == ERROR_SUCCESS) {
RequestChangeTheme::post(value == 0 ? "Dark" : "Light"); RequestChangeTheme::post(value == 0 ? "Dark" : "Light");
} else {
ImHexApi::System::impl::setBorderlessWindowMode(false);
} }
} else {
ImHexApi::System::impl::setBorderlessWindowMode(false);
} }
}); });
@ -51,13 +47,6 @@ static void detectSystemTheme() {
}); });
} }
static void checkBorderlessWindowOverride() {
bool borderlessWindowForced = ContentRegistry::Settings::read<bool>("hex.builtin.setting.interface", "hex.builtin.setting.interface.force_borderless_window_mode", false);
if (borderlessWindowForced)
ImHexApi::System::impl::setBorderlessWindowMode(true);
}
IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") { IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") {
using namespace hex::plugin::windows; using namespace hex::plugin::windows;
@ -71,5 +60,4 @@ IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") {
registerSettings(); registerSettings();
detectSystemTheme(); detectSystemTheme();
checkBorderlessWindowOverride();
} }