Allow setting arbitrary mime types
This commit is contained in:
parent
0e7da8643e
commit
45b408a78b
8
glfw/input.c
vendored
8
glfw/input.c
vendored
@ -1551,9 +1551,13 @@ GLFWAPI void glfwSetClipboardDataTypes(GLFWClipboardType clipboard_type, const c
|
|||||||
_glfw_free_clipboard_data(cd);
|
_glfw_free_clipboard_data(cd);
|
||||||
cd->get_data = get_data;
|
cd->get_data = get_data;
|
||||||
cd->mime_types = calloc(num_mime_types, sizeof(char*));
|
cd->mime_types = calloc(num_mime_types, sizeof(char*));
|
||||||
cd->num_mime_types = num_mime_types;
|
cd->num_mime_types = 0;
|
||||||
cd->ctype = clipboard_type;
|
cd->ctype = clipboard_type;
|
||||||
for (size_t i = 0; i < cd->num_mime_types; i++) cd->mime_types[i] = _glfw_strdup(mime_types[i]);
|
for (size_t i = 0; i < num_mime_types; i++) {
|
||||||
|
if (mime_types[i]) {
|
||||||
|
cd->mime_types[cd->num_mime_types++] = _glfw_strdup(mime_types[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
_glfwPlatformSetClipboard(clipboard_type);
|
_glfwPlatformSetClipboard(clipboard_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,11 +21,13 @@ class Clipboard:
|
|||||||
self.enabled = self.clipboard_type == GLFW_CLIPBOARD or supports_primary_selection
|
self.enabled = self.clipboard_type == GLFW_CLIPBOARD or supports_primary_selection
|
||||||
|
|
||||||
def set_text(self, x: Union[str, bytes]) -> None:
|
def set_text(self, x: Union[str, bytes]) -> None:
|
||||||
if self.enabled:
|
if isinstance(x, str):
|
||||||
self.data.clear()
|
x = x.encode('utf-8')
|
||||||
if isinstance(x, str):
|
self.set_mime({'text/plain': x})
|
||||||
x = x.encode('utf-8')
|
|
||||||
self.data['text/plain'] = x
|
def set_mime(self, data: Dict[str, DataType]) -> None:
|
||||||
|
if self.enabled and isinstance(data, dict):
|
||||||
|
self.data = data
|
||||||
set_clipboard_data_types(self.clipboard_type, tuple(self.data))
|
set_clipboard_data_types(self.clipboard_type, tuple(self.data))
|
||||||
|
|
||||||
def get_text(self) -> str:
|
def get_text(self) -> str:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user