Skip to content

Commit 5b5d36f

Browse files
4RH1T3CT0R7lanewei120
authored andcommitted
FIX: window drag lag and resize visual glitch on Windows
- Enable DWM composition via DwmExtendFrameIntoClientArea for smooth window dragging - Replace complete layout suppression with ~30fps throttling during interactive resize - Fire EVT_NOTICE_CHILDE_SIZE_CHANGED on WM_EXITSIZEMOVE for proper child updates - Fix switch fall-through in WM_GETMINMAXINFO case
1 parent 7e3cc1d commit 5b5d36f

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/slic3r/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ target_link_libraries(libslic3r_gui libslic3r cereal imgui imguizmo minilzo GLEW
691691
#target_link_libraries(libslic3r_gui libslic3r cereal imgui imguizmo minilzo GLEW::GLEW OpenGL::GL hidapi libcurl OpenSSL::SSL OpenSSL::Crypto ${wxWidgets_LIBRARIES} glfw)
692692

693693
if (MSVC)
694-
target_link_libraries(libslic3r_gui Setupapi.lib)
694+
target_link_libraries(libslic3r_gui Setupapi.lib dwmapi.lib)
695695
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
696696
FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server)
697697
FIND_LIBRARY(WAYLAND_EGL_LIBRARIES NAMES wayland-egl)

src/slic3r/GUI/MainFrame.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include <dbt.h>
7070
#include <shlobj.h>
7171
#include <shellapi.h>
72+
#include <dwmapi.h>
7273
#endif // _WIN32
7374
#include <slic3r/GUI/CreatePresetsDialog.hpp>
7475

@@ -185,6 +186,14 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
185186
set_miniaturizable(GetHandle());
186187
#endif
187188

189+
#ifdef _WIN32
190+
// Enable DWM hardware-accelerated compositing for this borderless window.
191+
// Without this, dragging the window by the title bar causes lag because
192+
// DWM can't efficiently composite a frameless window during drag.
193+
MARGINS margins = {0, 0, 0, 1};
194+
DwmExtendFrameIntoClientArea((HWND)GetHandle(), &margins);
195+
#endif
196+
188197
if (!wxGetApp().app_config->has("user_mode")) {
189198
wxGetApp().app_config->set("user_mode", "simple");
190199
wxGetApp().app_config->set_bool("developer_mode", false);
@@ -348,14 +357,16 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
348357
}
349358
#endif
350359
#ifdef _WIN32
351-
if (!m_is_in_move_or_resize) {
352-
#endif
353-
Refresh();
354-
Layout();
355-
wxQueueEvent(wxGetApp().plater(), new SimpleEvent(EVT_NOTICE_CHILDE_SIZE_CHANGED));
356-
#ifdef _WIN32
360+
if (m_is_in_move_or_resize) {
361+
ULONGLONG now = GetTickCount64();
362+
if (now - m_last_resize_layout_ms < 33)
363+
return;
364+
m_last_resize_layout_ms = now;
357365
}
358366
#endif
367+
Refresh();
368+
Layout();
369+
wxQueueEvent(wxGetApp().plater(), new SimpleEvent(EVT_NOTICE_CHILDE_SIZE_CHANGED));
359370
});
360371

361372
//BBS
@@ -821,14 +832,16 @@ WXLRESULT MainFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam
821832
AdjustWorkingAreaForAutoHide(hWnd, mmi);
822833
return 0;
823834
}
824-
}
835+
break;
836+
}
825837
case WM_ENTERSIZEMOVE:
826838
m_is_in_move_or_resize = true;
827839
break;
828840
case WM_EXITSIZEMOVE:
829841
m_is_in_move_or_resize = false;
830842
Refresh();
831843
Layout();
844+
wxQueueEvent(wxGetApp().plater(), new SimpleEvent(EVT_NOTICE_CHILDE_SIZE_CHANGED));
832845
break;
833846
}
834847
return wxFrame::MSWWindowProc(nMsg, wParam, lParam);

src/slic3r/GUI/MainFrame.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ class MainFrame : public DPIFrame
429429
uint32_t m_ulSHChangeNotifyRegister { 0 };
430430
static constexpr int WM_USER_MEDIACHANGED { 0x7FFF }; // WM_USER from 0x0400 to 0x7FFF, picking the last one to not interfere with wxWidgets allocation
431431
bool m_is_in_move_or_resize { false };
432+
ULONGLONG m_last_resize_layout_ms { 0 };
432433
#endif // _WIN32
433434
};
434435

0 commit comments

Comments
 (0)