mirror of
https://github.com/xenia-project/xenia.git
synced 2025-12-06 07:12:03 +01:00
Merge d3fcde2063 into 01ae24e46e
This commit is contained in:
commit
768f77a2d2
|
|
@ -26,6 +26,11 @@
|
||||||
#include <ShellScalingApi.h>
|
#include <ShellScalingApi.h>
|
||||||
#include <dwmapi.h>
|
#include <dwmapi.h>
|
||||||
|
|
||||||
|
DEFINE_uint32(window_position_x, 0,
|
||||||
|
"In windows the position to create the window to", "Display");
|
||||||
|
DEFINE_uint32(window_position_y, 0,
|
||||||
|
"In windows the position to create the window to", "Display");
|
||||||
|
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
|
|
@ -125,20 +130,35 @@ bool Win32Window::OpenImpl() {
|
||||||
dpi_, USER_DEFAULT_SCREEN_DPI));
|
dpi_, USER_DEFAULT_SCREEN_DPI));
|
||||||
AdjustWindowRectangle(window_size_rect, window_style,
|
AdjustWindowRectangle(window_size_rect, window_style,
|
||||||
BOOL(main_menu != nullptr), window_ex_style, dpi_);
|
BOOL(main_menu != nullptr), window_ex_style, dpi_);
|
||||||
|
|
||||||
|
int window_x = cvars::window_position_x;
|
||||||
|
int window_y = cvars::window_position_y;
|
||||||
|
if (window_x == 0 && window_y == 0) {
|
||||||
|
window_x = CW_USEDEFAULT;
|
||||||
|
window_y = CW_USEDEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
// Create the window. Though WM_NCCREATE will assign to `hwnd_` too, still do
|
// Create the window. Though WM_NCCREATE will assign to `hwnd_` too, still do
|
||||||
// the assignment here to handle the case of a failure after WM_NCCREATE, for
|
// the assignment here to handle the case of a failure after WM_NCCREATE, for
|
||||||
// instance.
|
// instance.
|
||||||
hwnd_ = CreateWindowExW(
|
hwnd_ = CreateWindowExW(
|
||||||
window_ex_style, L"XeniaWindowClass",
|
window_ex_style, L"XeniaWindowClass",
|
||||||
reinterpret_cast<LPCWSTR>(xe::to_utf16(GetTitle()).c_str()), window_style,
|
reinterpret_cast<LPCWSTR>(xe::to_utf16(GetTitle()).c_str()), window_style,
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
window_x, window_y, window_size_rect.right - window_size_rect.left,
|
||||||
window_size_rect.right - window_size_rect.left,
|
|
||||||
window_size_rect.bottom - window_size_rect.top, nullptr, nullptr,
|
window_size_rect.bottom - window_size_rect.top, nullptr, nullptr,
|
||||||
hinstance, this);
|
hinstance, this);
|
||||||
if (!hwnd_) {
|
if (!hwnd_) {
|
||||||
XELOGE("CreateWindowExW failed");
|
XELOGE("CreateWindowExW failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If saved window position is not in any monitor anymore, move window to
|
||||||
|
// the primary display
|
||||||
|
if (!MonitorFromWindow(hwnd_, MONITOR_DEFAULTTONULL)) {
|
||||||
|
MoveWindow(hwnd_, 0, 0, window_size_rect.right - window_size_rect.left,
|
||||||
|
window_size_rect.bottom - window_size_rect.top, false);
|
||||||
|
}
|
||||||
|
|
||||||
// For per-monitor DPI, obtain the DPI of the monitor the window was created
|
// For per-monitor DPI, obtain the DPI of the monitor the window was created
|
||||||
// on, and adjust the initial normal size for it. If as a result of this
|
// on, and adjust the initial normal size for it. If as a result of this
|
||||||
// resizing, the window is moved to a different monitor, the WM_DPICHANGED
|
// resizing, the window is moved to a different monitor, the WM_DPICHANGED
|
||||||
|
|
@ -1000,6 +1020,15 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||||
DeleteTimerQueueTimer(nullptr, cursor_auto_hide_timer_, nullptr);
|
DeleteTimerQueueTimer(nullptr, cursor_auto_hide_timer_, nullptr);
|
||||||
cursor_auto_hide_timer_ = nullptr;
|
cursor_auto_hide_timer_ = nullptr;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// Save window position
|
||||||
|
WINDOWINFO window_info{};
|
||||||
|
window_info.cbSize = sizeof(window_info);
|
||||||
|
if (GetWindowInfo(hwnd_, &window_info)) {
|
||||||
|
OVERRIDE_uint32(window_position_x, window_info.rcWindow.left);
|
||||||
|
OVERRIDE_uint32(window_position_y, window_info.rcWindow.top);
|
||||||
|
}
|
||||||
|
}
|
||||||
{
|
{
|
||||||
WindowDestructionReceiver destruction_receiver(this);
|
WindowDestructionReceiver destruction_receiver(this);
|
||||||
OnBeforeClose(destruction_receiver);
|
OnBeforeClose(destruction_receiver);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue