diff --git a/src/editor/Renderer.cpp b/src/editor/Renderer.cpp index 85a977e1..36102eba 100644 --- a/src/editor/Renderer.cpp +++ b/src/editor/Renderer.cpp @@ -67,6 +67,22 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) g_scroll += round(yoffset); } +void window_focus_callback(GLFWwindow* window, int focused) +{ + g_app->isFocused = focused; +} + +void cursor_enter_callback(GLFWwindow* window, int entered) +{ + g_app->isHovered = entered; +} + +void window_iconify_callback(GLFWwindow* window, int iconified) +{ + g_app->isIconified = iconified; +} + + Renderer::Renderer() { g_settings.loadDefault(); g_settings.load(); @@ -108,6 +124,9 @@ Renderer::Renderer() { glfwSetWindowPosCallback(window, window_pos_callback); glfwSetWindowCloseCallback(window, window_close_callback); glfwSetWindowMaximizeCallback(window, window_maximize_callback); + glfwSetWindowFocusCallback(window, window_focus_callback); + glfwSetCursorEnterCallback(window, cursor_enter_callback); + glfwSetWindowIconifyCallback(window, window_iconify_callback); glewInit(); @@ -488,6 +507,10 @@ void Renderer::renderLoop() { if (glerror != GL_NO_ERROR) { logf("Got OpenGL Error: %d\n", glerror); } + + if (!isFocused && !isHovered) { + sleepms(50); + } } glfwTerminate(); diff --git a/src/editor/Renderer.h b/src/editor/Renderer.h index 9c674882..97ab16e7 100644 --- a/src/editor/Renderer.h +++ b/src/editor/Renderer.h @@ -78,6 +78,9 @@ class Renderer { MergeResult mergeResult; bool hideGui = false; + bool isFocused = false; + bool isHovered = false; + bool isIconified = false; Renderer(); ~Renderer(); diff --git a/src/util/util.cpp b/src/util/util.cpp index 9235d3dd..6d165371 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -916,3 +916,13 @@ string getConfigDir() return string("") + getenv("HOME") + "/.config/bspguy/"; } #endif + + +void sleepms(uint32_t ms) +{ +#ifdef _WIN32 + Sleep(ms); +#else + usleep(ms * 1000); +#endif +} \ No newline at end of file diff --git a/src/util/util.h b/src/util/util.h index 727f53a3..ca7b9865 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -111,4 +111,6 @@ enum class FIXUPPATH_SLASH }; void fixupPath(std::string& path, FIXUPPATH_SLASH needstartslash, FIXUPPATH_SLASH needendslash); -void replaceAll(std::string& str, const std::string& from, const std::string& to); \ No newline at end of file +void replaceAll(std::string& str, const std::string& from, const std::string& to); + +void sleepms(uint32_t ms); \ No newline at end of file