From 6011ee2c64d28ba28bb1619f7b1269d876fd15f6 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sun, 16 Jun 2024 11:14:15 -0700 Subject: [PATCH] Implemented glfwGetClipboardString --- CMakeLists.txt | 2 +- README.md | 15 +++++++++++---- docs/Usage.md | 11 +++++++---- port/emscripten-glfw3.py | 4 ++-- src/cpp/emscripten/glfw3/Context.cpp | 17 ++++++++++++++++- src/cpp/emscripten/glfw3/Context.h | 2 ++ src/cpp/emscripten/glfw3/version.h | 2 +- src/cpp/glfw3.cpp | 12 +++++++++++- test/demo/shell.html | 1 + test/demo/src/Triangle.cpp | 3 +++ 10 files changed, 55 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55f4e12..8e23ec5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5) set(emscripten-glfw_RELEASE_YEAR "2024") set(emscripten-glfw_RELEASE_MONTH "06" ) -set(emscripten-glfw_RELEASE_DAY "01" ) +set(emscripten-glfw_RELEASE_DAY "16" ) set(emscripten-glfw_GLFW_VERSION "3.4.0") diff --git a/README.md b/README.md index ab04a18..75e40dd 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ Introduction This project is an emscripten port of GLFW written in C++ for the web/wasm platform. The currently supported GLFW API is 3.4. -[![Latest - 3.4.0.20240601](https://img.shields.io/badge/Latest-3.4.0.20240601-blue)](https://github.com/pongasoft/emscripten-glfw/releases/latest) +[![Latest - 3.4.0.20240616](https://img.shields.io/badge/Latest-3.4.0.20240616-blue)](https://github.com/pongasoft/emscripten-glfw/releases/latest) [![GLFW - 3.4.0](https://img.shields.io/badge/GLFW-3.4.0-blue)](https://www.glfw.org/) [![emscripten - TBD](https://img.shields.io/badge/emscripten-TBD-blue)](https://emscripten.org) ![Compiles](https://github.com/pongasoft/emscripten-glfw/actions/workflows/main.yml/badge.svg) -[![Previous - 3.4.0.20240514](https://img.shields.io/badge/Latest-3.4.0.20240514-blue)](https://github.com/pongasoft/emscripten-glfw/releases/latest) +[![Previous - 3.4.0.20240601](https://img.shields.io/badge/Previous-3.4.0.20240601-blue)](https://github.com/pongasoft/emscripten-glfw/releases/latest) [![GLFW - 3.4.0](https://img.shields.io/badge/GLFW-3.4.0-blue)](https://www.glfw.org/) -[![emscripten - 3.1.60](https://img.shields.io/badge/emscripten-3.1.60-blue)](https://emscripten.org) +[![emscripten - TBD](https://img.shields.io/badge/emscripten-TBD-blue)](https://emscripten.org) [![License](https://img.shields.io/badge/License-Apache%20License%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) @@ -154,6 +154,7 @@ emcc --use-port=contrib.glfw3:disableWarning=true:disableMultiWindow=true main.c > #### Note about availability in emscripten > | this port | emscripten | > |----------------|------------| +> | 3.4.0.20240616 | TBD | > | 3.4.0.20240601 | TBD | > | 3.4.0.20240514 | 3.1.60 | > | 3.4.0.20240501 | 3.1.60 | @@ -222,9 +223,15 @@ LDFLAGS += -s USE_WEBGPU=1 --js-library $(EMS_GLFW3_DIR)/src/js/lib_emscripten_g Release Notes ------------- +#### 3.4.0.20240616 - 2024-06-16 | emscripten TBD + +- Implemented `glfwGetClipboardString`. Note that due to the async (and restrictive) nature of the + `navigator.clipboard.readText` call, this synchronous API returns whatever was set via a previous call + to `glfwSetClipboardString` and ignores the external clipboard entirely. + #### 3.4.0.20240601 - 2024-06-01 | emscripten TBD -- Fixed #2: Dynamically changing HiDPI awareness does not trigger content callback +- Fixed [#2](https://github.com/pongasoft/emscripten-glfw/issues/2): Dynamically changing HiDPI awareness does not trigger content callback #### 3.4.0.20240514 - 2024-05-14 | emscripten 3.1.60 diff --git a/docs/Usage.md b/docs/Usage.md index cfc2a6b..77dc68d 100644 --- a/docs/Usage.md +++ b/docs/Usage.md @@ -136,9 +136,12 @@ Example code: position: absolute; bottom: 0; right: 0; - background-color: #444444; - width: 10px; - height: 10px; + margin-bottom: 1px; + margin-right: 1px; + border-left: 20px solid transparent; + border-bottom: 20px solid rgba(102, 102, 102, 0.5); + width: 0; + height: 0; cursor: nwse-resize; } @@ -359,6 +362,7 @@ This table contains the list of all the functions supported by this implementati | `glfwDestroyWindow` | Reverts all changes (event listeners, css style, ...) set by this library | | `glfwExtensionSupported` | Same implementation as `library_glfw.js` | | `glfwFocusWindow` | Calls javascript `HTMLElement.focus()` on the canvas | +| `glfwGetClipboardString` | Due to async nature of the browser API, only returns what was set via `glfwSetClipboardString` | | `glfwGetCurrentContext` | Only available if `glfwMakeContextCurrent` was called previously | | `glfwGetCursorPos` | Hi DPI aware | | `glfwGetError` | | @@ -453,7 +457,6 @@ Note that these functions log a warning the first time they are called (which ca | Function | Notes | |-------------------------------------|--------------------------------------------------------------| | `glfwDestroyCursor` | | -| `glfwGetClipboardString` | Access to clipboard is severally restricted in the browser | | `glfwGetGammaRamp` | No access from javascript | | `glfwGetMonitorPhysicalSize` | No access from javascript | | `glfwGetProcAddress` | Implemented by emscripten | diff --git a/port/emscripten-glfw3.py b/port/emscripten-glfw3.py index 3fa1307..53fe5c4 100644 --- a/port/emscripten-glfw3.py +++ b/port/emscripten-glfw3.py @@ -17,8 +17,8 @@ import os from typing import Dict -TAG = '3.4.0.20240601' -HASH = '3083c320b402fd97c3cf9b55c2c1025bb133b3de0ab32cbb4af13e2471f9a9202bb0c9ae11f578829ae59568bb332762a67686be33689b7803343b84d8032254' +TAG = '3.4.0.20240616' +HASH = 'a067effe2044020ed36199f7508c7ef143ee19b6d97e2e1e532974a97f8f2d510da486be0187630a9e0793a38ad7e67a52e74cddb40369c049b463cdebe304d4' ZIP_URL = f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip' # contrib port information (required) diff --git a/src/cpp/emscripten/glfw3/Context.cpp b/src/cpp/emscripten/glfw3/Context.cpp index 2aec382..9722f41 100644 --- a/src/cpp/emscripten/glfw3/Context.cpp +++ b/src/cpp/emscripten/glfw3/Context.cpp @@ -924,7 +924,22 @@ glfw_bool_t Context::isExtensionSupported(char const *extension) //------------------------------------------------------------------------ void Context::setClipboardString(char const *iContent) { - emscripten_glfw3_context_set_clipboard_string(iContent); + if(iContent) + { + emscripten_glfw3_context_set_clipboard_string(iContent); + fClipboardText = iContent; + } +} + +//------------------------------------------------------------------------ +// Context::getClipboardString +//------------------------------------------------------------------------ +char const *Context::getClipboardString() +{ + if(fClipboardText) + return fClipboardText->c_str(); + else + return nullptr; } } \ No newline at end of file diff --git a/src/cpp/emscripten/glfw3/Context.h b/src/cpp/emscripten/glfw3/Context.h index f8ede25..81b5240 100644 --- a/src/cpp/emscripten/glfw3/Context.h +++ b/src/cpp/emscripten/glfw3/Context.h @@ -92,6 +92,7 @@ class Context // clipboard void setClipboardString(char const *iContent); + char const *getClipboardString(); public: void onScaleChange(); @@ -130,6 +131,7 @@ class Context Config fConfig{}; float fScale{1.0f}; double fInitialTime{getPlatformTimerValue()}; + std::optional fClipboardText{}; std::optional fFullscreenRequest{}; std::optional fPointerLockRequest{}; diff --git a/src/cpp/emscripten/glfw3/version.h b/src/cpp/emscripten/glfw3/version.h index ceff135..6f31d87 100644 --- a/src/cpp/emscripten/glfw3/version.h +++ b/src/cpp/emscripten/glfw3/version.h @@ -22,7 +22,7 @@ namespace emscripten::glfw3 { -#define D_EMSCRIPTEN_GLFW_VERSION_STR "3.4.0.20240601" +#define D_EMSCRIPTEN_GLFW_VERSION_STR "3.4.0.20240616" } diff --git a/src/cpp/glfw3.cpp b/src/cpp/glfw3.cpp index da4c452..5eb4cf6 100644 --- a/src/cpp/glfw3.cpp +++ b/src/cpp/glfw3.cpp @@ -1230,6 +1230,17 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string) context->setClipboardString(string); } +//------------------------------------------------------------------------ +// glfwGetClipboardString +//------------------------------------------------------------------------ +GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window) +{ + auto context = getContext(); + if(context) + return context->getClipboardString(); + return nullptr; +} + //------------------------------------------------------------------------ // no implementation for the emscripten platform //------------------------------------------------------------------------ @@ -1267,7 +1278,6 @@ GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GL GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun callback) { logNotImplemented("glfwSetWindowIconifyCallback"); return callback; } GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun callback) { logNotImplemented("glfwSetWindowMaximizeCallback"); return callback; } GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun callback) { logNotImplemented("glfwSetDropCallback"); return callback; } -GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window) { logNotImplemented("glfwGetClipboardString"); return nullptr; } GLFWAPI void glfwSwapBuffers(GLFWwindow* window) { logNotImplemented("glfwSwapBuffers"); } // GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) { logNotImplemented("glfwGetProcAddress"); } implemented by emscripten GL GLFWAPI int glfwVulkanSupported(void) { return GLFW_FALSE; } diff --git a/test/demo/shell.html b/test/demo/shell.html index 061835d..83306a3 100644 --- a/test/demo/shell.html +++ b/test/demo/shell.html @@ -184,6 +184,7 @@ glfwGetWindowAttrib(GLFW_SCALE_FRAMEBUFFER)-- glfwGetTime- glfwGetTimerValue- + glfwGetClipboardString- glfwGetJoystickName- diff --git a/test/demo/src/Triangle.cpp b/test/demo/src/Triangle.cpp index c78f6a3..d204e7f 100644 --- a/test/demo/src/Triangle.cpp +++ b/test/demo/src/Triangle.cpp @@ -446,6 +446,9 @@ void Triangle::updateNoWindowValues() { setHtmlValue(nullptr, "glfwGetTime", "%.2f", glfwGetTime()); setHtmlValue(nullptr, "glfwGetTimerValue", "%ld", glfwGetTimerValue()); + auto clipboardText = glfwGetClipboardString(nullptr); + if(clipboardText) + setHtmlValue(nullptr, "glfwGetClipboardString", "%s", clipboardText); static std::vector jids{};