Skip to content

Commit

Permalink
Implemented glfwGetClipboardString
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jun 16, 2024
1 parent d789dc1 commit 6011ee2
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
</style>
Expand Down Expand Up @@ -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` | |
Expand Down Expand Up @@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions port/emscripten-glfw3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion src/cpp/emscripten/glfw3/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
2 changes: 2 additions & 0 deletions src/cpp/emscripten/glfw3/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Context

// clipboard
void setClipboardString(char const *iContent);
char const *getClipboardString();

public:
void onScaleChange();
Expand Down Expand Up @@ -130,6 +131,7 @@ class Context
Config fConfig{};
float fScale{1.0f};
double fInitialTime{getPlatformTimerValue()};
std::optional<std::string> fClipboardText{};

std::optional<Window::FullscreenRequest> fFullscreenRequest{};
std::optional<Window::PointerLockRequest> fPointerLockRequest{};
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/emscripten/glfw3/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}

Expand Down
12 changes: 11 additions & 1 deletion src/cpp/glfw3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//------------------------------------------------------------------------
Expand Down Expand Up @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions test/demo/shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<tr class="glfwGetWindowAttrib-scale_framebuffer"><td>glfwGetWindowAttrib(GLFW_SCALE_FRAMEBUFFER)</td><td class="canvas1">-</td><td class="canvas2">-</td></tr>
<tr class="glfwGetTime"><td>glfwGetTime</td><td class="no-canvas" colspan="2">-</td></tr>
<tr class="glfwGetTimerValue"><td>glfwGetTimerValue</td><td class="no-canvas" colspan="2">-</td></tr>
<tr class="glfwGetClipboardString"><td>glfwGetClipboardString</td><td class="no-canvas" colspan="2">-</td></tr>
</tbody>
<tbody id="joystick">
<tr class="glfwGetJoystickName"><td>glfwGetJoystickName</td><td class="no-canvas" colspan="2">-</td></tr>
Expand Down
3 changes: 3 additions & 0 deletions test/demo/src/Triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> jids{};

Expand Down

0 comments on commit 6011ee2

Please sign in to comment.