void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods ) { if (action != GLFW_PRESS) return; if (key == GLFW_KEY_ESCAPE && mods == 0) glfwSetWindowShouldClose(window, GLFW_TRUE); if ((key == GLFW_KEY_ENTER && mods == GLFW_MOD_ALT) || (key == GLFW_KEY_F11 && mods == GLFW_MOD_ALT)) { if (glfwGetWindowMonitor(window)) { glfwSetWindowMonitor(window, NULL, windowed_xpos, windowed_ypos, windowed_width, windowed_height, 0); } else { GLFWmonitor* monitor = glfwGetPrimaryMonitor(); if (monitor) { const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwGetWindowPos(window, &windowed_xpos, &windowed_ypos); glfwGetWindowSize(window, &windowed_width, &windowed_height); glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); } } } }
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (action != GLFW_PRESS) return; switch (key) { case GLFW_KEY_UP: { if (swap_interval + 1 > swap_interval) set_swap_interval(window, swap_interval + 1); break; } case GLFW_KEY_DOWN: { if (swap_tear) { if (swap_interval - 1 < swap_interval) set_swap_interval(window, swap_interval - 1); } else { if (swap_interval - 1 >= 0) set_swap_interval(window, swap_interval - 1); } break; } case GLFW_KEY_ESCAPE: glfwSetWindowShouldClose(window, 1); break; case GLFW_KEY_F11: case GLFW_KEY_ENTER: { static int x, y, width, height; if (mods != GLFW_MOD_ALT) return; if (glfwGetWindowMonitor(window)) glfwSetWindowMonitor(window, NULL, x, y, width, height, 0); else { GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwGetWindowPos(window, &x, &y); glfwGetWindowSize(window, &width, &height); glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); } break; } } }
JNIEXPORT jlong JNICALL Java_com_badlogic_jglfw_Glfw_glfwGetWindowMonitor(JNIEnv* env, jclass clazz, jlong window) { //@line:792 return (jlong)glfwGetWindowMonitor((GLFWwindow*)window); }
static void set_gamma(GLFWwindow* window, float value) { GLFWmonitor* monitor = glfwGetWindowMonitor(window); if (!monitor) monitor = glfwGetPrimaryMonitor(); gamma_value = value; printf("Gamma: %f\n", gamma_value); glfwSetGamma(monitor, gamma_value); }
int Graphics::GetCurrentMonitor() { GLFWmonitor *mon = glfwGetWindowMonitor(window2_); int moncount=0; GLFWmonitor **monitors = glfwGetMonitors(&moncount); while(--moncount>=0) if(monitors[moncount]==mon) return moncount; return 0; }
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { printf("%0.2f Key %s\n", glfwGetTime(), action == GLFW_PRESS ? "pressed" : "released"); if (action != GLFW_PRESS) return; switch (key) { case GLFW_KEY_I: glfwIconifyWindow(window); break; case GLFW_KEY_M: glfwMaximizeWindow(window); break; case GLFW_KEY_R: glfwRestoreWindow(window); break; case GLFW_KEY_ESCAPE: glfwSetWindowShouldClose(window, GLFW_TRUE); break; case GLFW_KEY_F11: case GLFW_KEY_ENTER: { if (mods != GLFW_MOD_ALT) return; if (glfwGetWindowMonitor(window)) { glfwSetWindowMonitor(window, NULL, windowed_xpos, windowed_ypos, windowed_width, windowed_height, 0); } else { GLFWmonitor* monitor = glfwGetPrimaryMonitor(); if (monitor) { const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwGetWindowPos(window, &windowed_xpos, &windowed_ypos); glfwGetWindowSize(window, &windowed_width, &windowed_height); glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); } } break; } } }
bool Window::switchFullscreen(int screenId) { int count; GLFWmonitor** monitors = glfwGetMonitors(&count); if (screenId >= count) return false; if (_window.get() == nullptr) return false; if (screenId != -1) _screenId = screenId; else if (screenId == _screenId) return true; const GLFWvidmode* vidmode = glfwGetVideoMode(monitors[_screenId]); glfwWindowHint(GLFW_VISIBLE, true); GLFWwindow* window; if (glfwGetWindowMonitor(_window->get()) == NULL) { glfwWindowHint(GLFW_RED_BITS, vidmode->redBits); glfwWindowHint(GLFW_GREEN_BITS, vidmode->greenBits); glfwWindowHint(GLFW_BLUE_BITS, vidmode->blueBits); glfwWindowHint(GLFW_REFRESH_RATE, vidmode->refreshRate); window = glfwCreateWindow(vidmode->width, vidmode->height, ("Splash::" + _name).c_str(), monitors[_screenId], _window->getMainWindow()); } else window = glfwCreateWindow(vidmode->width, vidmode->height, ("Splash::" + _name).c_str(), 0, _window->getMainWindow()); if (!window) { Log::get() << Log::WARNING << "Window::" << __FUNCTION__ << " - Unable to create new fullscreen shared window" << Log::endl; return false; } _window = move(make_shared<GlWindow>(window, _window->getMainWindow())); updateSwapInterval(); setupReadFBO(); setEventsCallbacks(); showCursor(false); return true; }
static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (action == GLFW_PRESS) { if (key == GLFW_KEY_ESCAPE) { glfwSetWindowShouldClose(window, GLFW_TRUE); } else if (key == GLFW_KEY_F11 || key == GLFW_KEY_ENTER && mods == GLFW_MOD_ALT) { static int last_window_xpos, last_window_ypos; static int last_window_width, last_window_height; VK_CHECK(vkDeviceWaitIdle(vk.device)); GLFWmonitor* monitor = glfwGetWindowMonitor(window); if (monitor == nullptr) { glfwGetWindowPos(window, &last_window_xpos, &last_window_ypos); last_window_width = window_width; last_window_height = window_height; monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); } else { glfwSetWindowMonitor(window, nullptr, last_window_xpos, last_window_ypos, last_window_width, last_window_height, 0); } } } }
Window::Window(GLFWwindow *window) : window(window) { glfwGetWindowSize(this->window, &this->width, &this->height); fullscreen = glfwGetWindowMonitor(this->window) != nullptr; // TODO: get title }
int main() { GLFWwindow *window; char *userptr = "userptr"; glfwSetErrorCallback(errorcb); assert(glfwInit() == GL_TRUE); assert(!strcmp(glfwGetVersionString(), "3.2.1 JS WebGL Emscripten")); assert(glfwGetCurrentContext() == NULL); { int major, minor, rev; glfwGetVersion(&major, &minor, &rev); assert(major == 3); assert(minor == 2); assert(rev == 1); } { int count, x, y, w, h; GLFWmonitor **monitors = glfwGetMonitors(&count); assert(count == 1); for (int i = 0; i < count; ++i) { assert(monitors[i] != NULL); } assert(glfwGetPrimaryMonitor() != NULL); glfwGetMonitorPos(monitors[0], &x, &y); glfwGetMonitorPhysicalSize(monitors[0], &w, &h); assert(glfwGetMonitorName(monitors[0]) != NULL); glfwSetMonitorCallback(monitcb); // XXX: not implemented // assert(glfwGetVideoModes(monitors[0], &count) != NULL); // assert(glfwGetVideoMode(monitors[0]) != NULL); // glfwSetGamma(monitors[0], 1.0f); // assert(glfwGetGammaRamp(monitors[0]) != NULL); // glfwSetGammaRamp(monitors[0], ramp); } { int x, y, w, h; glfwDefaultWindowHints(); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL); assert(window != NULL); glfwSetWindowPosCallback(window, wposicb); glfwSetWindowSizeCallback(window, wsizecb); glfwSetWindowCloseCallback(window, wcloscb); glfwSetWindowRefreshCallback(window, wrfrscb); glfwSetWindowFocusCallback(window, wfocucb); glfwSetWindowIconifyCallback(window, wiconcb); glfwSetFramebufferSizeCallback(window, wfsizcb); assert(glfwWindowShouldClose(window) == 0); glfwSetWindowShouldClose(window, 1); assert(glfwWindowShouldClose(window) == 1); glfwSetWindowTitle(window, "test"); glfwSetWindowTitle(window, "glfw3.c"); // XXX: not implemented // glfwSetWindowPos(window, 1, 1); glfwGetWindowPos(window, &x, &y); // stub glfwGetWindowSize(window, &w, &h); assert(w == 640 && h == 480); glfwSetWindowSize(window, 1, 1); glfwGetWindowSize(window, &w, &h); assert(w == 1 && h == 1); glfwSetWindowSize(window, 640, 480); glfwGetFramebufferSize(window, &w, &h); // XXX: not implemented // glfwIconifyWindow(window); // glfwRestoreWindow(window); // glfwShowWindow(window); // glfwHideWindow(window); assert(glfwGetWindowMonitor(window) == NULL); glfwDestroyWindow(window); window = glfwCreateWindow(640, 480, "glfw3.c", glfwGetPrimaryMonitor(), NULL); assert(window != NULL); assert(glfwGetWindowMonitor(window) == glfwGetPrimaryMonitor()); glfwDestroyWindow(window); window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL); assert(window != NULL); assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == GLFW_OPENGL_ES_API); assert(glfwGetWindowUserPointer(window) == NULL); glfwSetWindowUserPointer(window, userptr); assert(glfwGetWindowUserPointer(window) == userptr); } { double x, y; glfwSetKeyCallback(window, wkeypcb); glfwSetCharCallback(window, wcharcb); glfwSetMouseButtonCallback(window, wmbutcb); glfwSetCursorPosCallback(window, wcurpcb); glfwSetCursorEnterCallback(window, wcurecb); glfwSetScrollCallback(window, wscrocb); // XXX: stub, events come immediatly // glfwPollEvents(); // glfwWaitEvents(); assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL); // XXX: not implemented // glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwGetKey(window, GLFW_KEY_A); glfwGetMouseButton(window, 0); glfwGetCursorPos(window, &x, &y); // XXX: not implemented // glfwSetCursorPos(window, 0, 0); } { // XXX: not implemented // glfwJoystickPresent(joy); // glfwGetJoystickAxes(joy, &count); // glfwGetJoystickButtons(joy, &count); // glfwGetJoystickName(joy); } { // XXX: not implemented // glfwSetClipboardString(window, "string"); // glfwGetClipboardString(window); } { glfwGetTime(); glfwSetTime(0); } { glfwMakeContextCurrent(window); // stub assert(glfwGetCurrentContext() == window); glfwSwapBuffers(window); // stub glfwSwapInterval(0); // stub } { assert(glfwExtensionSupported("nonexistant") == 0); assert(glfwGetProcAddress("nonexistant") == NULL); } glfwTerminate(); #ifdef REPORT_RESULT REPORT_RESULT(1); #endif return 0; }
bool GetFullscreen() override { return this->_fullscreen || glfwGetWindowMonitor(this->_window) != NULL || this->GetWindowSize() == this->_getCurrentScreenSize(); }
// -------------------------------------------------------------------------------------------------------------------- bool window::fullscreen() const { return _internal && glfwGetWindowMonitor(_internal->_window); }