|
@@ -302,32 +302,34 @@ set_properties_now(WindowProperties &properties) {
|
|
|
// When switching undecorated mode, Windows will keep the window at the
|
|
// When switching undecorated mode, Windows will keep the window at the
|
|
|
// current outer size, whereas we want to keep it with the configured
|
|
// current outer size, whereas we want to keep it with the configured
|
|
|
// inner size. Store the current size and origin.
|
|
// inner size. Store the current size and origin.
|
|
|
- LPoint2i top_left = _properties.get_origin();
|
|
|
|
|
- LPoint2i bottom_right = top_left + _properties.get_size();
|
|
|
|
|
-
|
|
|
|
|
- DWORD window_style = make_style(_properties);
|
|
|
|
|
- DWORD current_style = GetWindowLong(_hWnd, GWL_STYLE);
|
|
|
|
|
- SetWindowLong(_hWnd, GWL_STYLE, window_style);
|
|
|
|
|
-
|
|
|
|
|
- // If we switched to/from undecorated, calculate the new size.
|
|
|
|
|
- if (((window_style ^ current_style) & WS_CAPTION) != 0) {
|
|
|
|
|
- RECT view_rect;
|
|
|
|
|
- SetRect(&view_rect, top_left[0], top_left[1],
|
|
|
|
|
- bottom_right[0], bottom_right[1]);
|
|
|
|
|
- WINDOWINFO wi;
|
|
|
|
|
- GetWindowInfo(_hWnd, &wi);
|
|
|
|
|
- AdjustWindowRectEx(&view_rect, wi.dwStyle, FALSE, wi.dwExStyle);
|
|
|
|
|
-
|
|
|
|
|
- SetWindowPos(_hWnd, HWND_NOTOPMOST, view_rect.left, view_rect.top,
|
|
|
|
|
- view_rect.right - view_rect.left,
|
|
|
|
|
- view_rect.bottom - view_rect.top,
|
|
|
|
|
- SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED |
|
|
|
|
|
- SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
|
|
|
|
|
- } else {
|
|
|
|
|
- // We need to call this to ensure that the style change takes effect.
|
|
|
|
|
- SetWindowPos(_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
|
|
|
|
|
- SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE |
|
|
|
|
|
- SWP_FRAMECHANGED | SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
|
|
|
|
|
|
|
+ if (_parent_window_handle == nullptr) {
|
|
|
|
|
+ LPoint2i top_left = _properties.get_origin();
|
|
|
|
|
+ LPoint2i bottom_right = top_left + _properties.get_size();
|
|
|
|
|
+
|
|
|
|
|
+ DWORD window_style = make_style(_properties);
|
|
|
|
|
+ DWORD current_style = GetWindowLong(_hWnd, GWL_STYLE);
|
|
|
|
|
+ SetWindowLong(_hWnd, GWL_STYLE, window_style);
|
|
|
|
|
+
|
|
|
|
|
+ // If we switched to/from undecorated, calculate the new size.
|
|
|
|
|
+ if (((window_style ^ current_style) & WS_CAPTION) != 0) {
|
|
|
|
|
+ RECT view_rect;
|
|
|
|
|
+ SetRect(&view_rect, top_left[0], top_left[1],
|
|
|
|
|
+ bottom_right[0], bottom_right[1]);
|
|
|
|
|
+ WINDOWINFO wi;
|
|
|
|
|
+ GetWindowInfo(_hWnd, &wi);
|
|
|
|
|
+ AdjustWindowRectEx(&view_rect, wi.dwStyle, FALSE, wi.dwExStyle);
|
|
|
|
|
+
|
|
|
|
|
+ SetWindowPos(_hWnd, HWND_NOTOPMOST, view_rect.left, view_rect.top,
|
|
|
|
|
+ view_rect.right - view_rect.left,
|
|
|
|
|
+ view_rect.bottom - view_rect.top,
|
|
|
|
|
+ SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED |
|
|
|
|
|
+ SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // We need to call this to ensure that the style change takes effect.
|
|
|
|
|
+ SetWindowPos(_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
|
|
|
|
|
+ SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE |
|
|
|
|
|
+ SWP_FRAMECHANGED | SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -464,7 +466,9 @@ set_properties_now(WindowProperties &properties) {
|
|
|
// Fall through
|
|
// Fall through
|
|
|
|
|
|
|
|
case WindowProperties::M_confined:
|
|
case WindowProperties::M_confined:
|
|
|
- if (confine_cursor()) {
|
|
|
|
|
|
|
+ // If we are not the foreground window, we defer confining the cursor
|
|
|
|
|
+ // until we are.
|
|
|
|
|
+ if (GetForegroundWindow() != _hWnd || confine_cursor()) {
|
|
|
_properties.set_mouse_mode(properties.get_mouse_mode());
|
|
_properties.set_mouse_mode(properties.get_mouse_mode());
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
@@ -505,6 +509,11 @@ close_window() {
|
|
|
set_cursor_out_of_window();
|
|
set_cursor_out_of_window();
|
|
|
DestroyWindow(_hWnd);
|
|
DestroyWindow(_hWnd);
|
|
|
|
|
|
|
|
|
|
+ if (_properties.has_mouse_mode() &&
|
|
|
|
|
+ _properties.get_mouse_mode() != WindowProperties::M_absolute) {
|
|
|
|
|
+ ClipCursor(nullptr);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (is_fullscreen()) {
|
|
if (is_fullscreen()) {
|
|
|
// revert to default display mode.
|
|
// revert to default display mode.
|
|
|
do_fullscreen_disable();
|
|
do_fullscreen_disable();
|
|
@@ -797,7 +806,7 @@ do_reshape_request(int x_origin, int y_origin, bool has_origin,
|
|
|
GetWindowInfo(_hWnd, &wi);
|
|
GetWindowInfo(_hWnd, &wi);
|
|
|
AdjustWindowRectEx(&view_rect, wi.dwStyle, FALSE, wi.dwExStyle);
|
|
AdjustWindowRectEx(&view_rect, wi.dwStyle, FALSE, wi.dwExStyle);
|
|
|
|
|
|
|
|
- UINT flags = SWP_NOZORDER | SWP_NOSENDCHANGING;
|
|
|
|
|
|
|
+ UINT flags = SWP_NOZORDER | SWP_NOSENDCHANGING | SWP_NOACTIVATE;
|
|
|
|
|
|
|
|
if (has_origin) {
|
|
if (has_origin) {
|
|
|
x_origin = view_rect.left;
|
|
x_origin = view_rect.left;
|
|
@@ -813,12 +822,6 @@ do_reshape_request(int x_origin, int y_origin, bool has_origin,
|
|
|
view_rect.bottom - view_rect.top,
|
|
view_rect.bottom - view_rect.top,
|
|
|
flags);
|
|
flags);
|
|
|
|
|
|
|
|
- // If we are in confined mode, we must update the clip region.
|
|
|
|
|
- if (_properties.has_mouse_mode() &&
|
|
|
|
|
- _properties.get_mouse_mode() == WindowProperties::M_confined) {
|
|
|
|
|
- confine_cursor();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
handle_reshape();
|
|
handle_reshape();
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -868,6 +871,28 @@ handle_reshape() {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // If we are in confined mode, we must update the clip region. However,
|
|
|
|
|
+ // we ony do that if the cursor in currently inside the window, to properly
|
|
|
|
|
+ // handle the case where someone is resizing the window straight after
|
|
|
|
|
+ // switching to it (you can do this if you press the start menu key to
|
|
|
|
|
+ // deactive the window, and then trying to resize it)
|
|
|
|
|
+ if (_properties.has_mouse_mode() &&
|
|
|
|
|
+ _properties.get_mouse_mode() != WindowProperties::M_absolute &&
|
|
|
|
|
+ _hWnd == GetForegroundWindow()) {
|
|
|
|
|
+
|
|
|
|
|
+ POINT cpos;
|
|
|
|
|
+ if (GetCursorPos(&cpos) && PtInRect(&view_rect, cpos)) {
|
|
|
|
|
+ windisplay_cat.info()
|
|
|
|
|
+ << "ClipCursor() to " << view_rect.left << "," << view_rect.top
|
|
|
|
|
+ << " to " << view_rect.right << "," << view_rect.bottom << endl;
|
|
|
|
|
+
|
|
|
|
|
+ if (!ClipCursor(&view_rect)) {
|
|
|
|
|
+ windisplay_cat.warning()
|
|
|
|
|
+ << "Failed to re-confine cursor to window.\n";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
WindowProperties properties;
|
|
WindowProperties properties;
|
|
|
properties.set_size((view_rect.right - view_rect.left),
|
|
properties.set_size((view_rect.right - view_rect.left),
|
|
|
(view_rect.bottom - view_rect.top));
|
|
(view_rect.bottom - view_rect.top));
|
|
@@ -1008,7 +1033,7 @@ do_windowed_switch() {
|
|
|
|
|
|
|
|
// If we had a confined cursor, we must reconfine it now.
|
|
// If we had a confined cursor, we must reconfine it now.
|
|
|
if (_properties.has_mouse_mode() &&
|
|
if (_properties.has_mouse_mode() &&
|
|
|
- _properties.get_mouse_mode() == WindowProperties::M_confined) {
|
|
|
|
|
|
|
+ _properties.get_mouse_mode() != WindowProperties::M_absolute) {
|
|
|
confine_cursor();
|
|
confine_cursor();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1049,12 +1074,12 @@ make_style(const WindowProperties &properties) {
|
|
|
|
|
|
|
|
if (properties.get_fullscreen()) {
|
|
if (properties.get_fullscreen()) {
|
|
|
window_style |= WS_POPUP | WS_SYSMENU;
|
|
window_style |= WS_POPUP | WS_SYSMENU;
|
|
|
- } else {
|
|
|
|
|
- if (_parent_window_handle) {
|
|
|
|
|
- window_style |= WS_CHILD;
|
|
|
|
|
- } else {
|
|
|
|
|
- window_style |= WS_POPUP;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (_parent_window_handle) {
|
|
|
|
|
+ window_style |= WS_CHILD;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ window_style |= WS_POPUP;
|
|
|
|
|
|
|
|
if (!properties.get_undecorated()) {
|
|
if (!properties.get_undecorated()) {
|
|
|
window_style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
|
|
window_style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
|
|
@@ -1585,7 +1610,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
|
|
|
|
|
|
|
// If we had a confined cursor, we must reconfine it upon activation.
|
|
// If we had a confined cursor, we must reconfine it upon activation.
|
|
|
if (_properties.has_mouse_mode() &&
|
|
if (_properties.has_mouse_mode() &&
|
|
|
- _properties.get_mouse_mode() == WindowProperties::M_confined) {
|
|
|
|
|
|
|
+ _properties.get_mouse_mode() != WindowProperties::M_absolute) {
|
|
|
if (!confine_cursor()) {
|
|
if (!confine_cursor()) {
|
|
|
properties.set_mouse_mode(WindowProperties::M_absolute);
|
|
properties.set_mouse_mode(WindowProperties::M_absolute);
|
|
|
}
|
|
}
|
|
@@ -1631,7 +1656,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
|
|
|
|
|
|
|
// If we had a confined cursor, we must reconfine it upon a resize.
|
|
// If we had a confined cursor, we must reconfine it upon a resize.
|
|
|
if (_properties.has_mouse_mode() &&
|
|
if (_properties.has_mouse_mode() &&
|
|
|
- _properties.get_mouse_mode() == WindowProperties::M_confined) {
|
|
|
|
|
|
|
+ _properties.get_mouse_mode() != WindowProperties::M_absolute) {
|
|
|
confine_cursor();
|
|
confine_cursor();
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|