Skip to content

Commit d6d635d

Browse files
committed
core (win32): get rid of rounded corners when maximize
1 parent e035c2a commit d6d635d

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 4.0)
1+
cmake_minimum_required(VERSION 4.1)
22
project(Lazap VERSION 0.9.0)
33

44
#-----------------------------------------------------------------------------------------------------------------------

include/application.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ struct RunnerState {
3333
};
3434

3535
struct WindowCallbacks {
36-
static void mouse_button_callback(GLFWwindow* window, int button, int action,
37-
int mods);
38-
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos);
36+
static void mouseButtonCB(GLFWwindow* window, int button, int action,
37+
int mods);
38+
static void cursorPosCB(GLFWwindow* window, double xpos, double ypos);
3939
};
4040

4141
void IdleBySleeping(FpsIdling& ioIdling);

src/core/application.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ void IdleBySleeping(FpsIdling &ioIdling) {
5353
}
5454
}
5555

56+
#ifdef _WIN32
57+
void UpdateWindowCorners(GLFWwindow *window) {
58+
HWND hwnd = glfwGetWin32Window(window);
59+
60+
WINDOWPLACEMENT placement = {};
61+
placement.length = sizeof(WINDOWPLACEMENT);
62+
GetWindowPlacement(hwnd, &placement);
63+
64+
bool isMaximized = (placement.showCmd == SW_SHOWMAXIMIZED);
65+
66+
DWM_WINDOW_CORNER_PREFERENCE cornerPref =
67+
isMaximized ? DWMWCP_DONOTROUND : DWMWCP_ROUND;
68+
DwmSetWindowAttribute(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, &cornerPref,
69+
sizeof(cornerPref));
70+
}
71+
#endif
72+
5673
void Application::run() {
5774
auto startupBegin = std::chrono::high_resolution_clock::now();
5875

@@ -104,8 +121,8 @@ void Application::run() {
104121

105122
glfwSetWindowUserPointer(window, resizeState);
106123

107-
glfwSetMouseButtonCallback(window, WindowCallbacks::mouse_button_callback);
108-
glfwSetCursorPosCallback(window, WindowCallbacks::cursor_pos_callback);
124+
glfwSetMouseButtonCallback(window, WindowCallbacks::mouseButtonCB);
125+
glfwSetCursorPosCallback(window, WindowCallbacks::cursorPosCB);
109126

110127
Storage storage;
111128
storage.initTOML();
@@ -146,9 +163,6 @@ void Application::run() {
146163
HWND hwnd = glfwGetWin32Window(window);
147164
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
148165

149-
MARGINS margins = {1, 1, 1, 1};
150-
DwmExtendFrameIntoClientArea(hwnd, &margins);
151-
152166
DWM_WINDOW_CORNER_PREFERENCE cornerPref = DWMWCP_ROUND;
153167
DwmSetWindowAttribute(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, &cornerPref,
154168
sizeof(cornerPref));
@@ -160,6 +174,10 @@ void Application::run() {
160174

161175
glfwPollEvents();
162176

177+
#ifdef _WIN32
178+
UpdateWindowCorners(window);
179+
#endif
180+
163181
int display_w, display_h;
164182
glfwGetFramebufferSize(window, &display_w, &display_h);
165183
glViewport(0, 0, display_w, display_h);
@@ -186,8 +204,8 @@ void Application::run() {
186204
glfwTerminate();
187205
}
188206

189-
void WindowCallbacks::mouse_button_callback(GLFWwindow *window, int button,
190-
int action, int mods) {
207+
void WindowCallbacks::mouseButtonCB(GLFWwindow *window, int button, int action,
208+
int mods) {
191209
if (button != GLFW_MOUSE_BUTTON_LEFT) return;
192210

193211
ResizeState *state =
@@ -217,8 +235,8 @@ void WindowCallbacks::mouse_button_callback(GLFWwindow *window, int button,
217235
}
218236
}
219237

220-
void WindowCallbacks::cursor_pos_callback(GLFWwindow *window, double xpos,
221-
double ypos) {
238+
void WindowCallbacks::cursorPosCB(GLFWwindow *window, double xpos,
239+
double ypos) {
222240
ResizeState *state =
223241
static_cast<ResizeState *>(glfwGetWindowUserPointer(window));
224242
if (!state) return;

0 commit comments

Comments
 (0)