WIndows fix bug in RestoreFromFullscreen
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m39s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m39s
This commit is contained in:
@@ -220,13 +220,12 @@ public:
|
||||
/// @note Execution of the parent window is stopped while the message box is up.
|
||||
void DialogOK(const std::string& title, const std::string& message);
|
||||
|
||||
/// Sets whether or not to make the window fullscreen.
|
||||
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
|
||||
/// Sets whether the window is fullscreen.
|
||||
void SetFullscreen(bool fs);
|
||||
|
||||
/// Sets whether or not to make the window resizable.
|
||||
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
|
||||
void SetResizable(bool resizable);
|
||||
/// Sets whether the window can be resized by the user.
|
||||
/// @note Resize events will still be sent if fullscreen is toggled.
|
||||
void DisableResizing();
|
||||
|
||||
/// Sets the title of this window.
|
||||
void SetTitle(const std::string& title);
|
||||
@@ -265,7 +264,7 @@ public:
|
||||
void SetSize(const std::pair<int, int>& size);
|
||||
|
||||
/// Returns the position of the window's top-left corner relative to the display
|
||||
[[nodiscard]] std::pair<int, int> GetPos() const;
|
||||
[[nodiscard]] std::pair<int, int> GetPosition() const;
|
||||
|
||||
/// Returns the known size of the window, in {x,y} pixel measurement.
|
||||
[[nodiscard]] std::pair<int, int> GetSize() const;
|
||||
|
6
main.cpp
6
main.cpp
@@ -14,8 +14,10 @@ class MyWindow : public OpenGLWindow {
|
||||
void OnMouseMove(const MouseMoveEvent& e) override {}
|
||||
|
||||
void OnKeyDown(const KeyDownEvent& e) override {
|
||||
if (e.key == Keys::F11)
|
||||
if (e.key == Keys::F11) {
|
||||
SetFullscreen(!IsFullscreen());
|
||||
std::cout << "ran" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
bool OnResizeRequest(const WindowResizeRequestEvent& e) override { return true; }
|
||||
@@ -53,7 +55,7 @@ int main() {
|
||||
|
||||
Logger::Debug("TODO: Cannot set flags until after window is open");
|
||||
window->SetVsyncEnabled(true);
|
||||
window->SetResizable(true);
|
||||
window->DisableResizing();
|
||||
window->SetKeyRepeatEnabled(false);
|
||||
|
||||
Logger::Debug(std::format
|
||||
|
@@ -23,6 +23,7 @@ public:
|
||||
XWMHints* wm_hints = nullptr;
|
||||
bool window_visible = true;
|
||||
std::pair<int, int> position = { 0, 0 };
|
||||
std::pair<int, int> size_before_fullscreen {0, 0};
|
||||
};
|
||||
|
||||
|
||||
@@ -197,17 +198,15 @@ void RWindow::SetCursorVisible(bool cursor_enable) {
|
||||
XUndefineCursor(platform->display, platform->window);
|
||||
}
|
||||
|
||||
void RWindow::SetResizable(bool sizable) {
|
||||
void RWindow::DisableResizing() {
|
||||
XGetWindowAttributes(platform->display, platform->window, &platform->windowAttributes);
|
||||
|
||||
this->resizable = sizable;
|
||||
if (!sizable) {
|
||||
Logger::Debug("Once you've done this you cannot make it resizable again.");
|
||||
platform->hints.flags = PMinSize | PMaxSize;
|
||||
platform->hints.min_width = platform->hints.max_width = platform->windowAttributes.width;
|
||||
platform->hints.min_height = platform->hints.max_height = platform->windowAttributes.height;
|
||||
XSetWMNormalHints(platform->display, platform->window, &platform->hints);
|
||||
}
|
||||
|
||||
this->resizable = false;
|
||||
}
|
||||
|
||||
void RWindow::PollEvents() {
|
||||
@@ -411,16 +410,13 @@ bool RWindow::IsVisible() const {
|
||||
return platform->window_visible;
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, int> RWindow::GetSize() const {
|
||||
return { this->width, this->height };
|
||||
}
|
||||
|
||||
// TODO: implement integer std::pair<int, int>/3 types
|
||||
std::pair<int, int> RWindow::GetPos() const {
|
||||
std::pair<int, int> RWindow::GetPosition() const {
|
||||
return platform->position;
|
||||
}
|
||||
|
||||
std::pair<int, int> RWindow::GetSize() const { return { this->width, this->height }; }
|
||||
|
||||
void RWindow::SetPosition(int x, int y) {
|
||||
XMoveWindow(platform->display, platform->window, x, y);
|
||||
platform->position = {x, y};
|
||||
@@ -431,6 +427,19 @@ void RWindow::SetPosition(const std::pair<int, int>& pos) {
|
||||
}
|
||||
|
||||
void RWindow::Fullscreen() {
|
||||
platform->size_before_fullscreen = GetSize();
|
||||
|
||||
if (!this->resizable) {
|
||||
XSizeHints hints;
|
||||
hints.flags = PMinSize | PMaxSize;
|
||||
hints.min_width = 0;
|
||||
hints.min_height = 0;
|
||||
hints.max_width = 100000;
|
||||
hints.max_height = 100000;
|
||||
XSetWMNormalHints(platform->display, platform->window, &hints);
|
||||
XFlush(platform->display);
|
||||
}
|
||||
|
||||
Atom wm_state = XInternAtom(platform->display, "_NET_WM_STATE", False);
|
||||
Atom wm_fullscreen = XInternAtom(platform->display, "_NET_WM_STATE_FULLSCREEN", False);
|
||||
|
||||
@@ -450,13 +459,11 @@ void RWindow::Fullscreen() {
|
||||
xev.xclient.data.l[3] = 1;
|
||||
xev.xclient.data.l[4] = 0;
|
||||
|
||||
XSendEvent(
|
||||
platform->display,
|
||||
XSendEvent(platform->display,
|
||||
DefaultRootWindow(platform->display),
|
||||
False,
|
||||
SubstructureNotifyMask | SubstructureRedirectMask,
|
||||
&xev
|
||||
);
|
||||
&xev);
|
||||
|
||||
XFlush(platform->display);
|
||||
fullscreen_mode = true;
|
||||
@@ -491,7 +498,19 @@ void RWindow::RestoreFromFullscreen() {
|
||||
&xev
|
||||
);
|
||||
|
||||
if (!this->resizable) {
|
||||
XSizeHints hints;
|
||||
hints.flags = PMinSize | PMaxSize;
|
||||
hints.min_width = hints.max_width = platform->size_before_fullscreen.first;
|
||||
hints.min_height = hints.max_height = platform->size_before_fullscreen.second;
|
||||
XSetWMNormalHints(platform->display, platform->window, &hints);
|
||||
|
||||
this->width = platform->size_before_fullscreen.first;
|
||||
this->height = platform->size_before_fullscreen.second;
|
||||
}
|
||||
|
||||
XFlush(platform->display);
|
||||
|
||||
fullscreen_mode = false;
|
||||
Logger::Debug(std::format("Restored '{}' from Fullscreen", this->title));
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include <ReWindow/Logger.h>
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
RWindow::~RWindow() {
|
||||
if (open)
|
||||
DestroyOSWindowHandle();
|
||||
@@ -112,21 +113,21 @@ int RWindow::GetWidth() const { return this->width; }
|
||||
|
||||
int RWindow::GetHeight() const { return this->height; }
|
||||
|
||||
bool RWindow::IsResizable() const { return resizable; }
|
||||
bool RWindow::IsResizable() const { return resizable; }
|
||||
|
||||
bool RWindow::IsFullscreen() const { return fullscreen_mode; }
|
||||
bool RWindow::IsFullscreen() const { return fullscreen_mode; }
|
||||
|
||||
bool RWindow::IsFocused() const { return focused; }
|
||||
bool RWindow::IsFocused() const { return focused; }
|
||||
|
||||
bool RWindow::IsVsyncEnabled() const { return vsync; }
|
||||
bool RWindow::IsVsyncEnabled() const { return vsync; }
|
||||
|
||||
float RWindow::GetDeltaTime() const { return delta_time; }
|
||||
float RWindow::GetDeltaTime() const { return delta_time; }
|
||||
|
||||
float RWindow::GetRefreshRate() const { return refresh_rate; }
|
||||
float RWindow::GetRefreshRate() const { return refresh_rate; }
|
||||
|
||||
bool RWindow::SetCursorPosition(const int x, const int y) { return SetCursorPosition({x, y}); }
|
||||
|
||||
unsigned long long RWindow::GetRefreshCount() const { return refresh_count; }
|
||||
unsigned long long RWindow::GetRefreshCount() const { return refresh_count; }
|
||||
|
||||
void RWindow::SetSizeWithoutEvent(const std::pair<int, int>& size) {
|
||||
width = size.first;
|
||||
@@ -152,8 +153,7 @@ bool RWindow::IsMouseButtonDown(const MouseButton& button) const {
|
||||
}
|
||||
|
||||
|
||||
void RWindow::ManagedRefresh()
|
||||
{
|
||||
void RWindow::ManagedRefresh() {
|
||||
auto begin = GetTimestamp();
|
||||
Refresh();
|
||||
auto end = GetTimestamp();
|
||||
@@ -187,7 +187,7 @@ float RWindow::ComputeElapsedFrameTimeSeconds(std::chrono::steady_clock::time_po
|
||||
return frame_time_s;
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point RWindow::GetTimestamp() {
|
||||
std::chrono::steady_clock::time_point RWindow::GetTimestamp() {
|
||||
return std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
@@ -204,8 +204,7 @@ void RWindow::UpdateFrameTiming(float frame_time) {
|
||||
}
|
||||
|
||||
|
||||
void RWindow::processMouseWheel(int scrolls)
|
||||
{
|
||||
void RWindow::processMouseWheel(int scrolls) {
|
||||
currentMouse.Wheel += scrolls;
|
||||
auto ev = MouseWheelEvent(scrolls);
|
||||
OnMouseWheel(ev);
|
||||
@@ -214,17 +213,17 @@ void RWindow::processMouseWheel(int scrolls)
|
||||
previousMouse.Wheel = currentMouse.Wheel;
|
||||
}
|
||||
|
||||
void RWindow::Close() {
|
||||
void RWindow::Close() {
|
||||
closing = true;
|
||||
processOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
void RWindow::ForceClose() {
|
||||
void RWindow::ForceClose() {
|
||||
Close();
|
||||
DestroyOSWindowHandle();
|
||||
}
|
||||
}
|
||||
|
||||
bool MouseState::IsDown(const MouseButton& btn) const {
|
||||
bool MouseState::IsDown(const MouseButton& btn) const {
|
||||
if (btn == MouseButtons::Left) return Buttons.LMB;
|
||||
if (btn == MouseButtons::Right) return Buttons.RMB;
|
||||
if (btn == MouseButtons::Middle) return Buttons.MMB;
|
||||
@@ -234,9 +233,9 @@ void RWindow::processMouseWheel(int scrolls)
|
||||
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
|
||||
|
||||
return false; // Unknown button?
|
||||
}
|
||||
}
|
||||
|
||||
void MouseState::Set(const MouseButton& btn, bool state) {
|
||||
void MouseState::Set(const MouseButton& btn, bool state) {
|
||||
if (btn == MouseButtons::Left) Buttons.LMB = state;
|
||||
if (btn == MouseButtons::Right) Buttons.RMB = state;
|
||||
if (btn == MouseButtons::Middle) Buttons.MMB = state;
|
||||
@@ -244,9 +243,9 @@ void RWindow::processMouseWheel(int scrolls)
|
||||
if (btn == MouseButtons::Mouse5) Buttons.SideButton2 = state;
|
||||
//if (btn == MouseButtons::MWheelUp) Buttons.MWheelUp = state;
|
||||
//if (btn == MouseButtons::MWheelDown) Buttons.MWheelDown = state;
|
||||
}
|
||||
}
|
||||
|
||||
bool &MouseState::operator [](const MouseButton& btn) {
|
||||
bool &MouseState::operator [](const MouseButton& btn) {
|
||||
if (btn == MouseButtons::Left) return Buttons.LMB;
|
||||
if (btn == MouseButtons::Right) return Buttons.RMB;
|
||||
if (btn == MouseButtons::Middle) return Buttons.MMB;
|
||||
@@ -256,4 +255,4 @@ void RWindow::processMouseWheel(int scrolls)
|
||||
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
|
||||
|
||||
throw std::invalid_argument("Attempted to handle unmapped mouse button.");
|
||||
}
|
||||
}
|
@@ -9,6 +9,8 @@ public:
|
||||
HINSTANCE hInstance;
|
||||
HWND hwnd;
|
||||
HDC hdc;
|
||||
std::pair<int, int> window_size_before_fullscreen;
|
||||
std::pair<int, int> window_position_before_fullscreen;
|
||||
};
|
||||
|
||||
using namespace ReWindow;
|
||||
@@ -253,16 +255,18 @@ void RWindow::DestroyOSWindowHandle() {
|
||||
DestroyWindow(platform->hwnd);
|
||||
}
|
||||
|
||||
void RWindow::SetResizable(bool resizable) {
|
||||
if (!resizable) {
|
||||
void RWindow::DisableResizing() {
|
||||
RECT rect;
|
||||
GetWindowRect(platform->hwnd, &rect);
|
||||
|
||||
LONG style = GetWindowLong(platform->hwnd, GWL_STYLE);
|
||||
style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
|
||||
|
||||
SetWindowLong(platform->hwnd, GWL_STYLE, style);
|
||||
SetWindowPos(platform->hwnd, nullptr, rect.left, rect.top, rect.right - rect.left,
|
||||
rect.bottom - rect.top, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
|
||||
}
|
||||
|
||||
this->resizable = false;
|
||||
}
|
||||
|
||||
void RWindow::SetSize(int newWidth, int newHeight) {
|
||||
@@ -292,13 +296,20 @@ void RWindow::SetKeyRepeatEnabled(bool state) {
|
||||
key_repeat = state;
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, int> RWindow::GetSize() const {
|
||||
RECT rect;
|
||||
GetClientRect(platform->hwnd, &rect);
|
||||
return { (rect.right - rect.left), (rect.bottom - rect.top) };
|
||||
}
|
||||
|
||||
std::pair<int, int> RWindow::GetPosition() const {
|
||||
RECT rect;
|
||||
if (GetWindowRect(platform->hwnd, &rect))
|
||||
return { rect.left, rect.top };
|
||||
|
||||
return { -1, -1 };
|
||||
}
|
||||
|
||||
void RWindow::SetPosition(int x, int y) {
|
||||
SetWindowPos(platform->hwnd, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
}
|
||||
@@ -308,16 +319,38 @@ void RWindow::SetPosition(const std::pair<int, int>& pos) {
|
||||
}
|
||||
|
||||
void RWindow::Fullscreen() {
|
||||
// Implement fullscreen
|
||||
platform->window_position_before_fullscreen = GetPosition();
|
||||
platform->window_size_before_fullscreen = GetSize();
|
||||
|
||||
platform->window_position_before_fullscreen = this->GetPosition();
|
||||
SetWindowLong(platform->hwnd, GWL_STYLE, GetWindowLong(platform->hwnd, GWL_STYLE) & ~WS_OVERLAPPEDWINDOW);
|
||||
SetWindowPos(platform->hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
|
||||
fullscreen_mode = true;
|
||||
}
|
||||
|
||||
void RWindow::RestoreFromFullscreen() {
|
||||
// Implement restore from fullscreen
|
||||
SetWindowLong(platform->hwnd, GWL_STYLE, GetWindowLong(platform->hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW);
|
||||
SetWindowPos(platform->hwnd, nullptr, 0, 0, width, height, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
|
||||
|
||||
RECT rect = {0, 0, platform->window_size_before_fullscreen.first, platform->window_size_before_fullscreen.second };
|
||||
|
||||
AdjustWindowRectEx(&rect, GetWindowLong(platform->hwnd, GWL_STYLE), FALSE, GetWindowLong(platform->hwnd, GWL_EXSTYLE));
|
||||
|
||||
int window_width = rect.right - rect.left;
|
||||
int window_height = rect.bottom - rect.top;
|
||||
|
||||
SetWindowPos(
|
||||
platform->hwnd,
|
||||
nullptr,
|
||||
platform->window_position_before_fullscreen.first,
|
||||
platform->window_position_before_fullscreen.second,
|
||||
window_width,
|
||||
window_height,
|
||||
SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER
|
||||
);
|
||||
|
||||
DisableResizing();
|
||||
this->width = platform->window_position_before_fullscreen.first;
|
||||
this->height = platform->window_position_before_fullscreen.second;
|
||||
fullscreen_mode = false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user