mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 01:49:44 +00:00
Fix the windows frame hang and center new windows
The frame is set up again after every window mode change, but it subclassed the window procedure each time and stored our own procedure as the original one. Every message we do not handle then went through CallWindowProc straight back into ourselves: the window hung, and repaint messages were lost with it, which is what broke the live rendering during a resize. The subclass is installed once now, while the window style is still re-applied on every mode change. New windows are also placed at the center of the monitor work area instead of the top left corner. This only happens where the platform lets the client place its window, which wayland does not.
This commit is contained in:
parent
68d4214627
commit
74a28cebe5
2 changed files with 35 additions and 3 deletions
|
|
@ -277,9 +277,15 @@ void frame_setup_native(
|
|||
style |= WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU;
|
||||
style &= ~WS_CAPTION;
|
||||
SetWindowLongPtr(hwnd, GWL_STYLE, style);
|
||||
original_window_proc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(
|
||||
hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(frame_window_proc)
|
||||
));
|
||||
// Only subclass once: storing our own procedure as the original one
|
||||
// would send every unhandled message back into it, forever.
|
||||
const LONG_PTR current = GetWindowLongPtr(hwnd, GWLP_WNDPROC);
|
||||
if (current != reinterpret_cast<LONG_PTR>(frame_window_proc)) {
|
||||
original_window_proc = reinterpret_cast<WNDPROC>(current);
|
||||
SetWindowLongPtr(
|
||||
hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(frame_window_proc)
|
||||
);
|
||||
}
|
||||
SetWindowPos(
|
||||
hwnd,
|
||||
nullptr,
|
||||
|
|
|
|||
|
|
@ -56,6 +56,16 @@ static bool use_engine_frame() {
|
|||
#endif
|
||||
}
|
||||
|
||||
/// @brief Whether the platform lets the client place its own window
|
||||
static bool can_place_window() {
|
||||
#if GLFW_VERSION_MAJOR > 3 || \
|
||||
(GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4)
|
||||
return glfwGetPlatform() != GLFW_PLATFORM_WAYLAND;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::unordered_set<std::string> supported_gl_extensions;
|
||||
static void window_size_callback(GLFWwindow* window, int width, int height);
|
||||
|
||||
|
|
@ -980,6 +990,22 @@ std::tuple<
|
|||
glfwTerminate();
|
||||
return {nullptr, nullptr};
|
||||
}
|
||||
if (can_place_window()) {
|
||||
int areaX = 0, areaY = 0, areaWidth = 0, areaHeight = 0;
|
||||
glfwGetMonitorWorkarea(
|
||||
glfwGetPrimaryMonitor(),
|
||||
&areaX,
|
||||
&areaY,
|
||||
&areaWidth,
|
||||
&areaHeight
|
||||
);
|
||||
glfwSetWindowPos(
|
||||
window,
|
||||
areaX + (areaWidth - width) / 2,
|
||||
areaY + (areaHeight - height) / 2
|
||||
);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glewExperimental = GL_TRUE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue