Linux Fullscreen Graphics Mode
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m47s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m47s
This commit is contained in:
9
main.cpp
9
main.cpp
@@ -13,7 +13,10 @@ class MyWindow : public OpenGLWindow {
|
|||||||
|
|
||||||
void OnMouseMove(const MouseMoveEvent& e) override {}
|
void OnMouseMove(const MouseMoveEvent& e) override {}
|
||||||
|
|
||||||
void OnKeyDown(const KeyDownEvent& e) override {}
|
void OnKeyDown(const KeyDownEvent& e) override {
|
||||||
|
if (e.key == Keys::F11)
|
||||||
|
SetFullscreen(!IsFullscreen());
|
||||||
|
}
|
||||||
|
|
||||||
bool OnResizeRequest(const WindowResizeRequestEvent& e) override { return true; }
|
bool OnResizeRequest(const WindowResizeRequestEvent& e) override { return true; }
|
||||||
|
|
||||||
@@ -37,9 +40,6 @@ class MyWindow : public OpenGLWindow {
|
|||||||
if (IsMouseButtonDown(MouseButtons::Mouse5))
|
if (IsMouseButtonDown(MouseButtons::Mouse5))
|
||||||
std::cout << "Mouse5 Mouse Button" << std::endl;
|
std::cout << "Mouse5 Mouse Button" << std::endl;
|
||||||
|
|
||||||
if (IsKeyDown(Keys::N))
|
|
||||||
std::cout << "Gotteem" << std::endl;
|
|
||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -52,7 +52,6 @@ int main() {
|
|||||||
Logger::Debug(std::format("Opened window '{}'", window->GetTitle()));
|
Logger::Debug(std::format("Opened window '{}'", window->GetTitle()));
|
||||||
|
|
||||||
Logger::Debug("TODO: Cannot set flags until after window is open");
|
Logger::Debug("TODO: Cannot set flags until after window is open");
|
||||||
window->SetFullscreen(false);
|
|
||||||
window->SetVsyncEnabled(true);
|
window->SetVsyncEnabled(true);
|
||||||
window->SetResizable(true);
|
window->SetResizable(true);
|
||||||
window->SetKeyRepeatEnabled(false);
|
window->SetKeyRepeatEnabled(false);
|
||||||
|
@@ -431,41 +431,68 @@ void RWindow::SetPosition(const std::pair<int, int>& pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RWindow::Fullscreen() {
|
void RWindow::Fullscreen() {
|
||||||
Logger::Info(std::format("Fullscreening '{}'", this->title));
|
Atom wm_state = XInternAtom(platform->display, "_NET_WM_STATE", False);
|
||||||
fullscreen_mode = true;
|
Atom wm_fullscreen = XInternAtom(platform->display, "_NET_WM_STATE_FULLSCREEN", False);
|
||||||
|
|
||||||
XEvent xev;
|
if (!wm_state || !wm_fullscreen) {
|
||||||
Atom wm_state = XInternAtom(platform->display, "_NET_WM_STATE", true);
|
Logger::Error("We don't have the required atom for fullscreen graphics mode?");
|
||||||
Atom wm_fullscreen = XInternAtom(platform->display, "_NET_WM_STATE_FULLSCREEN", true);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
XChangeProperty(platform->display, platform->window, wm_state, XA_ATOM, 32, PropModeReplace, (unsigned char *)&wm_fullscreen, 1);
|
XEvent xev{};
|
||||||
memset(&xev, 0, sizeof(xev));
|
|
||||||
xev.type = ClientMessage;
|
xev.type = ClientMessage;
|
||||||
xev.xclient.window = platform->window;
|
xev.xclient.window = platform->window;
|
||||||
xev.xclient.message_type = wm_state;
|
xev.xclient.message_type = wm_state;
|
||||||
xev.xclient.format = 32;
|
xev.xclient.format = 32;
|
||||||
xev.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD
|
xev.xclient.data.l[0] = 1;
|
||||||
xev.xclient.data.l[1] = fullscreen_mode;
|
xev.xclient.data.l[1] = wm_fullscreen;
|
||||||
xev.xclient.data.l[2] = 0;
|
xev.xclient.data.l[2] = 0;
|
||||||
XSendEvent(platform->display, DefaultRootWindow(platform->display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
xev.xclient.data.l[3] = 1;
|
||||||
|
xev.xclient.data.l[4] = 0;
|
||||||
|
|
||||||
|
XSendEvent(
|
||||||
|
platform->display,
|
||||||
|
DefaultRootWindow(platform->display),
|
||||||
|
False,
|
||||||
|
SubstructureNotifyMask | SubstructureRedirectMask,
|
||||||
|
&xev
|
||||||
|
);
|
||||||
|
|
||||||
|
XFlush(platform->display);
|
||||||
|
fullscreen_mode = true;
|
||||||
Logger::Debug(std::format("Fullscreened '{}'", this->title));
|
Logger::Debug(std::format("Fullscreened '{}'", this->title));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RWindow::RestoreFromFullscreen() {
|
void RWindow::RestoreFromFullscreen() {
|
||||||
Logger::Debug(std::format("Restoring '{}' from Fullscreen", this->title));
|
|
||||||
fullscreen_mode = false;
|
|
||||||
XEvent xev;
|
|
||||||
Atom wm_state = XInternAtom(platform->display, "_NET_WM_STATE", False);
|
Atom wm_state = XInternAtom(platform->display, "_NET_WM_STATE", False);
|
||||||
Atom fullscreen = XInternAtom(platform->display, "_NET_WM_STATE_FULLSCREEN", False);
|
Atom fullscreen = XInternAtom(platform->display, "_NET_WM_STATE_FULLSCREEN", False);
|
||||||
memset(&xev, 0, sizeof(xev));
|
|
||||||
|
if (!wm_state || !fullscreen) {
|
||||||
|
Logger::Error("We don't have the required atom for fullscreen graphics mode?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
XEvent xev{};
|
||||||
xev.type = ClientMessage;
|
xev.type = ClientMessage;
|
||||||
xev.xclient.window = platform->window;
|
xev.xclient.window = platform->window;
|
||||||
xev.xclient.message_type = wm_state;
|
xev.xclient.message_type = wm_state;
|
||||||
xev.xclient.format = 32;
|
xev.xclient.format = 32;
|
||||||
xev.xclient.data.l[0] = 0; // _NET_WM_STATE_REMOVE
|
xev.xclient.data.l[0] = 0;
|
||||||
xev.xclient.data.l[1] = fullscreen_mode;
|
xev.xclient.data.l[1] = fullscreen;
|
||||||
xev.xclient.data.l[2] = 0;
|
xev.xclient.data.l[2] = 0;
|
||||||
XSendEvent(platform->display, DefaultRootWindow(platform->display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
xev.xclient.data.l[3] = 1;
|
||||||
|
xev.xclient.data.l[4] = 0;
|
||||||
|
|
||||||
|
XSendEvent(
|
||||||
|
platform->display,
|
||||||
|
DefaultRootWindow(platform->display),
|
||||||
|
False,
|
||||||
|
SubstructureNotifyMask | SubstructureRedirectMask,
|
||||||
|
&xev
|
||||||
|
);
|
||||||
|
|
||||||
|
XFlush(platform->display);
|
||||||
|
fullscreen_mode = false;
|
||||||
Logger::Debug(std::format("Restored '{}' from Fullscreen", this->title));
|
Logger::Debug(std::format("Restored '{}' from Fullscreen", this->title));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user